题意:给定的这些点是否有一个对称中心。
PS:我写得有点啰嗦。。。。我也就写写这么挫的东东。。。
就是把小的x和大的x进行匹配。
#include<stdio.h> #include<algorithm> #include<math.h> using namespace std; const double eps = 1e-8; const int maxn = 10005; struct Point{ double x,y; }; Point pnt1[ maxn ],pnt2[ maxn ]; Point cc; int cmp1( Point a,Point b ){ return a.x<b.x; } int cmp2( Point a,Point b ){ return a.y<b.y; } int cmp3( Point a,Point b ){ return a.x>b.x; } bool NotOnePoint( Point a,Point b ){ if( fabs(a.x-b.x)<=eps&&fabs(a.y-b.y)<=eps ) return false; else return true; } bool OK( Point a,Point b ){ if( fabs((a.x+b.x)-(2.0*cc.x))<=eps && fabs((a.y+b.y)-(2.0*cc.y))<=eps ) return true; else return false; } bool Notcc( Point a ){ if( fabs(a.x-cc.x)<=eps&&fabs(a.y-cc.y)<=eps ) return true; else return false; } int main(){ int n; int T; //freopen("in.txt","r",stdin); scanf("%d",&T); while( T-- ){ scanf("%d",&n); for( int i=1;i<=n;i++ ){ scanf("%lf%lf",&pnt1[i].x,&pnt1[i].y); pnt2[ i ] = pnt1[ i ]; } if( n==2 ){ puts("yes"); continue; } sort( pnt1+1,pnt1+1+n,cmp1 ); cc.x = (pnt1[1].x+pnt1[n].x)/2.0; sort( pnt2+1,pnt2+1+n,cmp2 ); cc.y = (pnt2[1].y+pnt2[n].y)/2.0; sort( pnt2+1,pnt2+1+n,cmp3 ); int cnt = 0; if( n%2==1 ){ for( int i=1;i<=n;i++ ){ if( pnt1[i].x==cc.x&&pnt1[i].y==cc.y ){ cnt++; } } } if( (n-cnt)%2==1 ){ puts("no"); continue; } if( n==cnt ){ puts("yes"); continue; } //printf("cc:x = %lf,y = %lf\n",cc.x,cc.y); /* for( int i=1;i<=n;i++ ){ printf("x = %lf \n",pnt1[i].x); } for( int i=1;i<=n;i++ ){ printf("x = %lf \n",pnt2[i].x); } */ int tt = 0; int N = n - cnt;//N%2=0 for( int i=1;i<=(n/2)&&tt<(N/2);i++ ){ tt++; //printf(" i =%d ",i); //printf("pnt1:x = %lf y = %lf\n",pnt1[i].x,pnt1[i].y); bool find = false; for( int j=1;j<=(n/2);j++ ){ //printf(" j = %d \n",j); //printf("pnt2:x = %lf y = %lf\n",pnt2[j].x,pnt2[j].y); if( (pnt1[i].x+pnt2[j].x)<2.0*cc.x ) break; if( /*Notcc(pnt1[i])==true&&*/NotOnePoint(pnt1[i],pnt2[j])==true&&OK(pnt1[i],pnt2[j])==true ){ find = true; cnt += 2; break; } } //if( find==true ) printf("true\n"); //else printf("false\n"); if( find==false ) break; } if( cnt==n ){ puts("yes"); continue; } puts("no"); } return 0; }