UVa-1595 - Symmetry
在看了别人的代码后发现有很多可以避免出现精度问题的方法(如坐标都乘2等)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 const int maxx=1010; 7 const double eps=1e-5; 8 int main() 9 { 10 //freopen("in.txt","r",stdin); 11 //freopen("out.txt","w",stdout); 12 int T; 13 scanf("%d",&T); 14 while(T--) 15 { 16 int n; 17 scanf("%d",&n); 18 int x[maxx]={},y[maxx]={}; 19 double xx=0; 20 for(int i=1;i<=n;i++) 21 { 22 scanf("%d%d",&x[i],&y[i]); 23 xx+=x[i]; 24 } 25 xx/=n; 26 int i,j; 27 for(i=1;i<=n;i++) 28 { 29 for(j=1;j<=n;j++) 30 { 31 if(abs(2*xx-x[i]-x[j])<eps&&abs(y[i]-y[j])<eps) 32 break; 33 } 34 if(j>n) break; 35 } 36 puts(i>n?"YES":"NO"); 37 } 38 }