题意:给定的这些点是否有一个对称中心。

PS:我写得有点啰嗦。。

就是把小的x和大的x进行匹配。

 #include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std; const double eps = 1e-;
const int maxn = ; 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=;i<=n;i++ ){
scanf("%lf%lf",&pnt1[i].x,&pnt1[i].y);
pnt2[ i ] = pnt1[ i ];
}
if( n== ){
puts("yes");
continue;
}
sort( pnt1+,pnt1++n,cmp1 );
cc.x = (pnt1[].x+pnt1[n].x)/2.0;
sort( pnt2+,pnt2++n,cmp2 );
cc.y = (pnt2[].y+pnt2[n].y)/2.0;
sort( pnt2+,pnt2++n,cmp3 ); int cnt = ;
if( n%== ){
for( int i=;i<=n;i++ ){
if( pnt1[i].x==cc.x&&pnt1[i].y==cc.y ){
cnt++;
}
}
}
if( (n-cnt)%== ){
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 = ;
int N = n - cnt;//N%2=0
for( int i=;i<=(n/)&&tt<(N/);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=;j<=(n/);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 += ;
break;
}
}
//if( find==true ) printf("true\n");
//else printf("false\n");
if( find==false ) break;
}
if( cnt==n ){
puts("yes");
continue;
}
puts("no");
}
return ;
}
05-11 01:30