hdu5762Teacher Bo

来源:互联网 发布:调频发射软件 编辑:程序博客网 时间:2024/04/28 13:23

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5762

题意:给定n个点(x,y),求是否存在两对点对的曼哈顿距离相等。

分析:数据范围题。曼哈顿距离一定是0~2*10^5,如果不存在的话就最多只能有sqrt(2*10^5)个不同的曼哈顿距离咯。那么n<500暴力,n>=500直接输出yes即可。

代码:

#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<vector>#include<string>#include<stdio.h>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=100010;const int mod=100000000;const int MOD1=1000000007;const int MOD2=1000000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=1000000007;const int MAX=2000000010;const ll INF=1ll<<55;const double pi=acos(-1.0);typedef double db;typedef unsigned long long ull;struct node {    int x,y;}a[N];int d[300000];int main(){    int i,j,n,m,k,t,bo;    scanf("%d", &t);    while (t--) {        scanf("%d%d", &n, &m);        for (i=1;i<=n;i++) scanf("%d%d", &a[i].x, &a[i].y);        if (n>500) printf("YES\n");        else {            k=0;bo=0;            for (i=2;i<=n;i++)                for (j=1;j<i;j++) d[++k]=abs(a[i].x-a[j].x)+abs(a[i].y-a[j].y);            sort(d+1,d+k+1);            for (i=1;i<k;i++)            if (d[i]==d[i+1]) { bo=1;break ; }            if (bo) printf("YES\n");            else printf("NO\n");        }    }    return 0;}


0 0