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
"Problem Analysis"
When you see the problem, it collapses. Isn't that computational geometry? (I wouldn't t_t anyway) and then I saw the huge data of 100w.
Then I went to see the solution, only to know that such a thing like the geometry of the problem is to use a string method to solve. Instantly Orz the film down to the ground.
This idea: write this graphic in the form of a string s, then copy the SS again, then use its crossdress s ' to run aside and see how many times it can match. The answer is how much.
I think it's more appropriate to run Manacher and make statistics easier.
"Code" (the topic see crashes, the code is surprisingly short, but the examination room can think of this idea of the estimated also not much, I am not even violent people)
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <string>5 structed{6 intx, y;7}e[1001000];8 ints[4001000],r[4001000];9InlineintMinintAintb)Ten{returnA>b?b:a;} OneInlineintDisintAintb) A{return(e[a].x-e[b].x) * (e[a].x-e[b].x) + (E[A].Y-E[B].Y) * (e[a].y-e[b].y);} -InlineintCrointAintBintc) -{return(e[b].x-e[a].x) * (E[C].Y-E[A].Y)-(e[c].x-e[a].x) * (e[b].y-e[a].y);} the intMain () - { - inttt; -scanf"%d",&TT); + while(tt--) - { + intN; Ascanf"%d",&n); at for(intI=0; i<n;++i) -{scanf ("%d%d",&e[i].x,&e[i].y);} - for(intI=0; i<n;++i) s[i<<1|1]=dis (i, (i+1)%n); - for(intI=0; i<n;++i) s[i<<1]=cro (i, (i)1+n)%n, (i+1)%n); - intall=n<<1; for(intI=0; i<n;++i) s[i+all]=S[i]; -all<<=1; in intans=0, mx=0, id=0; Memset (R,0,sizeofR); - for(intI=0; i<all;++i) to { + if(mx>i) R[i]=min (mx-i,r[2*id-i]);Elser[i]=1; - while(i-r[i]>=0&&i+r[i]<=all&&s[i-r[i]]==s[i+r[i]]) r[i]++; the if(I+R[I]>MX) mx=i+r[i],id=i; * if(r[i]>=n+1) ans++; $ }Panax Notoginsengprintf"%d\n", ans); - } the return 0; +}
View Code
Bzoj 1100 [POI2007] symmetry OSI