题意:给n个点的坐标,求距离最近的一对点之间距离的一半。
分析:分治法求最近点对。
#include
#include
#include
using namespace std;
#define N 100005
double min(double a,double b)
{
return a<b?a:b;
}
struct POINT
{
double x,y;
};
POIN...
分类:
其他好文 时间:
2015-06-03 15:54:03
阅读次数:
135
分析:暴力,注意有公共点是指两个城池是否相邻。
#include
#include
using namespace std;
bool map[505][505];
vector vx;
vector vy;
int n,m;
bool judge(int x,int y)
{
bool t1,t2,t3,t4;
t1=t2=t3=t4=0;
if(x>1 && map[x-1][y...
分类:
其他好文 时间:
2015-06-03 10:04:18
阅读次数:
115
题意:一个数列,a1,a2,a3,a4,---,an,需要最少修改多少个元素,使得这个序列严格递增?
分析:因为a[i]=a[i],整理得a[i+1]-(i+1)>=a[i]-i。令b[i]=a[i]-i。则可以求出b[i]的最长不下降子序列的长度len,最后用n-len即为需要改变的最少的元素个数。
#include
#include
using namespace std;
int a[...
分类:
其他好文 时间:
2015-06-03 10:03:00
阅读次数:
121
分析:每个盘子都可以放到三个柱子上的任意一个,所以是3^n。
#include
using namespace std;
int main()
{
__int64 num[31]={1};
int i,t,n;
for(i=1;i<=30;i++)
num[i]=num[i-1]*3;
scanf("%d",&t);
while(t--)
{
scanf("...
分类:
其他好文 时间:
2015-06-02 23:27:13
阅读次数:
143
分析:两个人都足够聪明,因此每个阶段都拿最大的。dp[sa][ea][sb][eb]分别表示区间1的开始为sa,结束为ea,区间2的开始为sb,结束为eb时能拿到的最大值。之后分别从四个方向上拿,是个搜索的过程。
[cpp] view
plaincopyprint?
#include
using namespace std;
...
分类:
其他好文 时间:
2015-06-02 22:10:58
阅读次数:
164
分析:使用64位来保存整数,一个64位保存9位,最后920ms飘过,如果使用ASCII码模拟绝对TLE。貌似这题可以使用FFT(快速傅立叶变换)解决,但是这种方法比较复杂,还没有理解。
#include
using namespace std;
__int64 a[10001],b[10001]; //整数a,b,每个存储9位
__int64 ans[40001]; //...
分类:
其他好文 时间:
2015-06-02 21:57:07
阅读次数:
124
一、数论算法 1.求两数的最大公约数 2.求两数的最小公倍数 3.素数的求法 A.小范围内判断一个数是否为质数: B.判断longint范围内的数是否为素数(包含求50000以内的素数表):二、图论算法1.最小生成树A.Prim算法: B.Kruskal算法:(贪心) 按权值递增顺序删去图中的边,若...
分类:
编程语言 时间:
2015-06-02 21:53:26
阅读次数:
186
分析:并查集实现最小生成树。不能用cin和cout(使用了ios::sync_with_stdio(false);都不行),否则TLE。
#include
#include
#include
using namespace std;
#define N 1005
int father[N*N];
struct EDGE
{
int u,v;
int len;
bool operator...
分类:
其他好文 时间:
2015-06-02 20:11:10
阅读次数:
575
分析:水题,不解释。
#include
using namespace std;
int cnt[6000];
void init() //打表
{
int i,j;
memset(cnt,0,sizeof(cnt));
cnt[1]=1; //1只有他本身
for(i=2;i<=5005;i++)
{
cnt[i]+=2; //1和他本身
...
分类:
其他好文 时间:
2015-06-02 17:54:49
阅读次数:
223
分析:在除的过程中,当出现相同余数时即出现循环节。
#include
using namespace std;
bool h[100002];
void div(int x)
{
int t;
memset(h,false,x*sizeof(h[0])+1);
h[1]=true;
t=1;
while(t)
{
t=t*10;
cout<<t/x;
t=t%x;
...
分类:
其他好文 时间:
2015-06-02 17:51:31
阅读次数:
249