您的位置:首页 > 其它

hdu 5762 Teacher Bo(暴力美学)

2016-08-05 16:47 417 查看


这个题当时我写的时候一看,要把10^5个点组成的所有情况暴力一遍肯定T了,但又没有更好的方法,于是放弃了这道题

但后来才知道,它的坐标范围也就10^5,也就是说曼哈顿距离最大也就是2*10^5,遍历所有点肯定超时,但遍历所有曼哈顿距离时间肯定有多的

因为大不了最坏的情况是遍历的点集前2*10^5个全部都是不一样的,但是遍历的下一个点肯定与前面的2*10^5中的某一个情况有重合的,而这个时候就找到题目要求的点集了

所以现在我知道了,暴力的时候要看看有哪些对象可以暴力并选取最好的对象

代码:

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<iterator>
#include<stack>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const double eps=1e-8,PI=3.1415926538;
const LL MOD=1000000000+7;
const int INF=0x3f3f3f3f;
int n,m;
int x[100000+13],y[100000+13];
int bs(int t)
{
return t>0?t:-t;
}

int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d%d",&x[i],&y[i]);
}
bool dis[2*(100000+13)];
int flag=0;int dist;
memset(dis,false,sizeof(bool)*(100000+13)*2);
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
dist=(int)bs(x[i]-x[j])+(int)bs(y[i]-y[j]);
if(dis[dist])flag=1;
else dis[dist]=true;
if(flag)break;
}
if(flag)break;
}
if(flag)puts("YES");
else puts("NO");
}
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: