1100: [poi2007] symmetric axis ositime limit: 10 sec memory limit: 162 MB
Submit: 334 solved: 130
[Submit] [Status] Description
FGD Children-A famous young mathematician-have a small mm, yours. The FGD child liked his mm very much, so he was happy to help his mm with his math homework. However, like all scientific containers, the FGD brain refuses to repeatedly think about the same problem. Unfortunately, yours is a very diligent student, so she keeps asking FGD to help her check her homework. On a sunny weekend, yours math assigned a lot of questions about the symmetry axis of a polygon, which was enough for a long time. Before that, FGD decided to spend this rare holiday at the seaside, but he still felt that he should help his mm to deal with cute math jobs. Soon he found the solution, and it was better to write a program to help yours check her math homework. Because FGD is not a computer scientist, he found his good friend and asked you to help him complete the task. Write a program: Read the polygon description to calculate the number of symmetric axes of each polygon and output the calculation result.
Input
The first line of the input contains a positive integer T (1 <= T <= 10), which is the number of edges of the polygon. Next, for the description of T polygon, the first behavior of each description is a positive integer N (3 <= n <= 100000), indicating the points of the polygon. Then there are two integers x and y (−100000000 <= X, Y <= 100000000) in each row in the next n rows, which represent the vertex coordinates of the polygon in turn. Polygon is not necessarily convex, but not self-crossing-each side has only one or more public points-their public endpoints. In addition, there are no two consecutive edges parallel.
Output
Your program should output exactly t rows. The K rows contain an integer NK, which indicates the number of symmetric axes of the K polygon.
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
2 hint
Source
Question:
Interesting questions. The computation geometric taste is so strong that the character string algorithm is used to solve the problem.
I really have no idea about computational ry t_t.
Question handling of wyx528:
Consider how many symmetric axes a polygon has. We can represent a polygon as a sequence composed of edges and edges.
If the line I and J of a vertex are a symmetric axis, the two segments separated by the two vertices should be connected as a return string. The specific method is me.
Find a sequence with a length of 2n, the first is the side length, the second is the angle, the third is the side length, and so on. Remember that this string is S,
If we copy s to get the SS, and the reverse string of S is s', the original problem becomes how many times s appears in SS. This can be solved using KMP. Note:
If the angle will be inaccurate, you can use the cross product instead, because if the side length is not the same, the cross product will not work. If the side length is equal
.
The next part can also be directly written to manacher without real numbers and no precision error. orz
Code: some explanations are written in comments.
1 # include 2 # include 3 # include 4 # include 5 # include 6 # include 7 # include 8 # include 9 # include 10 # include 11 # include 12 # define INF 100000000013 # define maxn 100000 + 1014 # define maxm 500 + 10015 # define EPS 1e-1016 # define ll long long17 # define PA pair 18 # define for0 (I, n) for (INT I = 0; I <= (n); I ++) 19 # define for1 (I, n) for (INT I = 1; I <= (n); I ++) 20 # define for2 (I, x, y) for (INT I = (X ); I <= (y); I ++) 21 # define for3 (I, x, y) for (INT I = (x); I> = (y ); I --) 22 # define mod 100000000723 # define sqr (x) * (x) 24 using namespace STD; 25 inline ll read () 26 {27 ll x = 0, F = 1; char CH = getchar (); 28 while (CH <'0' | ch> '9') {If (CH = '-') F =-1; CH = getchar ();} 29 While (CH> = '0' & Ch <= '9 ') {x = 10 * x + CH-'0'; CH = getchar ();} 30 return x * F; 31} 32 int N, Cs, Lim, ANS, MX, ID, P [4 * maxn]; 33 struct rec {ll X, Y;} B [maxn]; 34 struct rec235 {36 bool type; // indicates the attribute of the point, is it angle or side 37 ll X; 38 friend bool operator = (rec2 A, rec2 B) 39 {40 return. type = B. type &. X = B. x; 41} 42} A [4 * maxn]; 43 inline ll dist (rec a, rec B) // the distance to the square 44 {45 return sqr (. x-b.x) + sqr (. y-b.y); 46} 47 inline ll cross (rec a, rec B, REC c) // Cross Product 48 {49 return (B. x-a.x) * (C. y-a.y)-(C. x-a.x) * (B. y-a.y); 50} 51 int main () 52 {53 freopen ("input.txt", "r", stdin); 54 freopen ("output.txt", "W", stdout ); 55 cs = read (); 56 while (Cs --) 57 {58 n = read (); 59 for0 (I, n-1) B [I]. X = read (), B [I]. y = read (); 60 for0 (I, n-1) 61 {62 A [I <1 | 1]. type = 1; 63 A [I <1 | 1]. X = dist (B [I], B [(I + 1) % N]); 64} 65 for0 (I, n-1) 66 {67 a [I <1]. type = 0; 68 A [I <1]. X = cross (B [I], B [(I-1 + n) % N], B [(I + 1) % N]); 69} 70 Lim = n <1; 71 for0 (I, lim-1) A [I + Lim] = A [I]; // assign the original string 72 Lim <= 1; 73 MX = id = 0; memset (p, 0, sizeof (p); 74 for0 (I, lim-1) 75 {76 if (MX> I) P [I] = min (P [2 * ID-I], Mx-I); 77 (; i-P [I]> = 0, I + P [I] MX) {MX = I + P [I]; id = I ;} 79} // manacher 80 ans = 0; 81 for0 (I, lim-1) if (P [I]-1> = N) ans ++; // each symmetric axis has two vertices: 82 printf ("% d \ n", ANS> 1); 83} 84 return 0; 85}View code
Bzoj1100: [poi2007] OSI symmetric axis