题意:给出n个点,判断是否有中心对称点。
题解:排序,验证
View Code
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 struct point 6 { 7 int x,y; 8 bool operator<(const point &ne)const 9 { 10 if(x!=ne.x) 11 return x<ne.x; 12 else 13 return y<ne.y; 14 } 15 bool operator!=(const point &ne)const 16 { 17 return x!=ne.x||y!=ne.y; 18 } 19 point(){} 20 point(int _x,int _y){x=_x;y=_y;} 21 }po[10005],p; 22 int main() 23 { 24 int T,n; 25 for(scanf("%d",&T);T;T--) 26 { 27 scanf("%d",&n); 28 for(int i=0;i<n;i++) 29 scanf("%d%d",&po[i].x,&po[i].y); 30 sort(po,po+n); 31 p=point(po[0].x+po[n-1].x,po[0].y+po[n-1].y); 32 for(int i=1,j=n-2;i<j;i++,j--) 33 { 34 if(p!=point(po[i].x+po[j].x,po[i].y+po[j].y)) 35 { 36 n=0; 37 break; 38 } 39 } 40 printf("%s\n",(n==0)?"no":"yes"); 41 } 42 return 0; 43 }