HDU 5762 Teacher Bo
因为m最多只有100000,也就是说曼哈顿距离最多只有200000种,所以找200000对必然能找到。这和367人里面必然有人生日重复一样的道理。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<iostream> using namespace std; typedef long long LL; const double pi = acos(-1.0), eps = 1e-8; void File() { freopen("D:\\in.txt", "r", stdin); freopen("D:\\out.txt", "w", stdout); } inline int read() { char c = getchar(); while (!isdigit(c)) c = getchar(); int x = 0; while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x; } const int maxn=100000+10; int T,x[maxn],y[maxn]; LL n,m; bool flag[2*maxn]; int main() { scanf("%d",&T); while(T--) { scanf("%lld%lld",&n,&m); for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]); int ans=0; memset(flag,0,sizeof flag); for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { if(flag[abs(x[i]-x[j])+abs(y[i]-y[j])]==1) { ans=1; break;} flag[abs(x[i]-x[j])+abs(y[i]-y[j])]=1; } if(ans==1) break; } if(ans==1) printf("YES\n"); else printf("NO\n"); } return 0; }