Description
After taking a modern art class, Farmer John had become interested in finding geometric patterns in everything around his Farm. He carefully plots the locations of his N cows (2 <= n <=), each one occupying a distinct point in the 2D plane , and he wonders how many different lines of symmetry exist for this set of points. A line of symmetry, of course, was a line across which the points in both sides is mirror images of each-other. FJ answer this pressing geometric question.
After a modern art class, FJ began to be interested in geometric patterns in his farm. He plans to place the cows on a two-dimensional plane of N distinct points (1<=n<=1000), and he wants to find out how many of the axis of symmetry the point set has. He desperately needs your help to solve this geometrical problem.
Input
* Line 1:the a single integer N.
* Lines 2..1+n:line i+1 contains, space-separated integers representing the x and Y coordinates of the ith cow ( -10,00 0 <= x, y <= 10,000).
Output
* Line 1:the number of different lines of symmetry of the set.
The whole point on the circle is very small, so you can find the center of gravity of the points and click the distance of the center of gravity to sort the points, to the same distance of the center of gravity at the same circle, calculate the symmetry axis of these points (up to four), the last intersection can be, time complexity is O (N2LOGN) but because the whole point
#include <bits/stdc++.h>typedefLong Doubleld;ConstLD Pi=std::acos (-1), _0=1e-7l;intn,ans=0, xs=0, ys=0, lp=0, ap=0, ad=0;structpos{intx, y;Long LongD;ld A;} ps[1007];ld ls[ -], as[ -];BOOL operator<(pos A,pos b) {returna.d!=b.d?a.d<b.d:a.a<B.A;} LD dis (ld x,ld y) {returnSTD::SQRT (x*x+y*y);}intFixintAintLintR) { if(a<l)returna+r-l; if(A>=R)returna-r+M; returnA;}BOOLfeq (ld a,ld b) {returnFabs (A-B) <_0;}BOOLchk (ld x) { while(x>pi*2-_0) x-=pi*2; while(x<_0-pi*2) x+=pi*2; returnStd::fabs (x) <_0;}intMain () {scanf ("%d",&N); for(intI=0; i<n;i++) scanf ("%d%d",&ps[i].x,&ps[i].y); for(intI=0; i<n;i++) {xs+=ps[i].x; Ys+=ps[i].y; } for(intI=0; i<n;i++) {(ps[i].x*=n)-=xs; (Ps[i].y*=n)-=Ys; PS[I].D=1ll*ps[i].x*ps[i].x+1ll*ps[i].y*ps[i].y; PS[I].A=atan2 (ps[i].y,ps[i].x); } std::sort (Ps,ps+N); intp0=0, p1; while(ps[p0].x==0&&ps[p0].y==0)++P0; for(p1=p0;p0<n;p0=p1) { while(P1<N&&PS[P1].D==PS[P0].D) + +P1; LP=0; for(intp2=p0;p2<p1;p2++){ BOOLab=1; LD M=ps[p2].a*2; for(intL=fix (p2-1, P0,P1), R=fix (p2+1, p0,p1);; L=fix (l1, P0,P1), R=fix (r+1, P0,P1)) { if(!chk (ps[l].a+ps[r].a-m)) {AB=0; Break; } if(L==R) Break; } if(ab==1) ls[lp++]=ps[p2].a; if(p1-p0&1)Continue; AB=1; M= (Ps[p2].a+ps[fix (p2+1, P0,P1)]. a); for(intL=fix (P2,P0,P1), R=fix (p2+1, P0,P1),t=p1-p0>>1; T;--t,l=fix (l1, P0,P1), R=fix (r+1, P0,P1)) { if(!chk (ps[l].a+ps[r].a-m)) {AB=0; Break; } if(L==R) Break; } if(AB) ls[lp++]=m/2.; } for(intI=0; i<lp;i++) {ld x=Ls[i]; while(X<-_0) x+=Pi; while(X>PI-_0) x-=Pi; Ls[i]=x; } std::sort (Ls,ls+LP); LP=std::unique (LS,LS+LP,FEQ)-ls; if(AD) {intlp1=0, ap1=0; for(intI=0; i<ap;i++){ while(lp1<lp&&ls[lp1]< as[i]-_0) + +LP1; if(LP1==LP) Break; if(Feq ( as[I],LS[LP1])) as[ap1++]= as[i]; } AP=AP1; }Else{AD=1; for(intI=0; i<lp;i++) as[ap++]=Ls[i]; }} printf ("%d", AP); return 0;}
bzoj2592: [Usaco2012 feb]symmetry