Title Address: http://acm.fzu.edu.cn/problem.php?pid=2035
In fact, the problem is the same: http://acm.hdu.edu.cn/showproblem.php?pid=3902
The topic is also very understood, is to deal with how to judge whether the multilateral line is symmetrical.
First find the midpoint of all points, then a total of 2xN points, and then check whether the XY line symmetry
If there is an axis of symmetry, it must be a straight line of point I and Point i+n, then verify the symmetrical points on both sides . is the distance between points I and point i+n equal
/* Determine if the N-side shape is an axisymmetric graphic: n Vertices of the nth-edged shape plus the midpoint of the N-side, a total of 2*n vertices. If there is an axis of symmetry, it must be a straight line of point I and Point i+n, and then verify that the distance between the symmetric point I and point i+n is equal, respectively./#include <stdio.h> #include <cmath>using namespace std; #define MAXN 20000#define EPS 1e-5struct node{double x, y;} Node[2*maxn+10];int N,m;bool flag;//is used to label whether it is an axisymmetric graphic double dis (int i,int j)//For Node[i] and Node[j] (distance {double x=node[i].x-node) [J].x; Double y=node[i].y-node[j].y; return sqrt (x*x+y*y);} BOOL Check (int i,int j,int x,int y)//check node[i] and node[j] whether about XY symmetry//symmetry then dis (i,x) ==dis (j,x) &&dis (i,y) ==dis (j,y); {if (Fabs (DIS (i,x)-dis (j,x)) >eps) return false; if (Fabs (DIS (i,y)-dis (j,y)) >eps) return false; return true;} void ff (int x,int y)//Judge Node[x] and Node[y] The line is not the axis of symmetry {int i,j; I=j=x; while (1) {i++;j--; if (j==0) j=m; if (i==y) {flag=true; Return } if (check (i,j,x,y) ==false) return; }} int main () {//freopen ("test.in", "R", stdin); Freopen ("Test.out", "w", stdout); IntI while (~SCANF ("%d", &n)) {m=2*n; for (i=1;i<=m;i+=2) {scanf ("%lf%lf", &node[i].x,&node[i].y); } Node[m+1]=node[1]; for (i=2;i<=m;i+=2) {node[i].x= (node[i-1].x+node[i+1].x)/2; node[i].y= (NODE[I-1].Y+NODE[I+1].Y)/2; } Flag=false; for (i=1;i<=n;i++) {ff (i,i+n); if (flag) break; } if (flag) printf ("yes\n"); else printf ("no\n"); } return 0; }
Judging the symmetry of multilateral lines