1100: [POI2007] symmetry OSI time limit:10 Sec Memory limit:162 MB
submit:630 solved:243
[Submit] [Status] [Discuss] Description
The FGD children--a young mathematician famous--has a small mm,yours. FGD children like his mm very much, so he is very happy
Help his mm to do maths homework. But, like all scientific containers, the FGD brain refuses to keep repeating the same questions. Unfortunately,
Yes, yours was a very hardworking student, so she kept getting fgd to help her check her homework. A sunny weekend, yours's math
The teacher laid out a lot of questions to look for the symmetry axis of the polygon, enough for her to do for quite a long time. Before that, FGD had decided to go to the seaside.
This rare holiday, but he still think should help his mm against cute math homework. Soon he found a solution, preferably writing a
Program to help yours check her math homework. Because FGD is not a computer scientist, so he found his good friend you, please help him finish
into this task. Please write a program: Read the description of the polygon to calculate the result output of the symmetric axis number of each polygon will be calculated
Input
The first line of the input contains a positive integer t (1<=t<=10), which is the number of sides of the polygon. Next, for the description of the T-polygon, each description of the first
The behavior is a positive integer n (3<=n<=100000) that represents the number of points in the polygon. Then two integers x and y (? 100000000<=x, Y<=1) on each row in the back n rows
00000000), which in turn represents the vertex coordinates of the polygon. Polygons are not necessarily convex, but do not self-cross--any two-sided edges have a maximum of one public
Points--their public endpoints. In addition, there are no two consecutive edges parallel.
Output
Your program should output just T-line, and the K-line contains an integer nk--that indicates how many axes of the K-polygon have.
Sample Input2
12
1-1
2-1
2 1
1 1
1 2
-1 2
-1 1
-2 1
-2-1
-1-1
-1-2
1-2
6
-1 1
-2 0
-1-1
1-1
2 0
1 1
Sample Output4
2HINT
Source [Submit] [Status] [Discuss]
Analysis
Summary: Polygon axis number, O (number of sides).
Far look at computational geometry, near-look at string processing, 2333~~~
Consider that if the polygon can be represented by a string, symmetry can be translated into a palindrome.
Then choose to use the length of each edge and the cross product of the two edges to represent the angle, which can be translated into a string.
Code
1#include <bits/stdc++.h>2 3Template <classInt>4Inline Int Sqr (ConstInt &num) {5 returnNum *num;6 }7 8Template <classInt>9Inline Int min (ConstInt &a,ConstInt &b) {Ten returnA < b?a:b; One } A - Const intMAXN =800005; - the intN; - intCAs; - intLen; - intX[MAXN]; + intY[MAXN]; - intS[MAXN]; + intR[MAXN]; A atInlineintCalc1 (intmid) { - intleft = (Mid-1+ N)%N; - intright = (Mid +1+ N)%N; - return -(X[left]-x[mid]) * (Y[mid]-Y[right]) --(Y[left]-y[mid]) * (X[mid]-x[right]); in } - toInlineintCALC2 (intLeft ) { + intright = (left +1+ N)%N; - return theSQR (X[left]-X[right]) *+ SQR (Y[left]-y[right]); $ }Panax Notoginseng -Signed Main (void) { thescanf"%d", &CAs); + while(cas--) { Ascanf"%d", &n); the for(inti =0; I < n; ++i) +scanf"%d%d", x + I, y +i); -memset (s),0,sizeof(s)); $ for(inti =0; I < n; ++i) { $S[i <<1] =Calc1 (i); -S[i <<1|1] =CALC2 (i); - } theLen = n <<1; - for(inti =0; I < n; ++i)WuyiS[len + i] =S[i]; theLen = n <<2; - intMaxi =0, id =0, answer =0; Wu for(inti =0; i < Len; ++i) { - if(Maxi >i) AboutR[i] = min (r[2*id-i], Maxi-i); $ Else -R[i] =1; - while(I-r[i] >=0&& i + r[i] <=Len -&& S[i-r[i] [= S[i + R[i]] + +R[i]; A if(Maxi < i +R[i]) +Maxi = i + r[i], id =i; the if(R[i] > N) + +answer; - } $printf"%d\n", answer); the } the}
Bzoj_1100.cpp
@Author: Yousiki
Bzoj 1100: [POI2007] The axis of symmetry OSI