Topic: Given a polygon, the number of axes of symmetry
I x this is how to think KMP ...
The Edge word Fu Hua is then found in the center of the polygon and represented by the edge-angle-edge of the triangle with the center.
Sweep the side clockwise over and then multiply to the length of 2n-1 and then counterclockwise sweep again, the number of times that appear in the clockwise that is the number of axes
With the KMP algorithm, you can prove yourself yy.
The accuracy of human card ...
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define M 100100#define EPS 1e-6using namespace std;struct point{double x,y;point () {}point (double _,double __): X (_), Y (__) {}void Read () {scanf ("%lf%lf", &x,&y);} void operator + = (Const point &y) {x+=y.x;y+=y.y;} Point operator-(const point &y) Const{return Point (X-Y.X,Y-Y.Y); Double operator * (const point &y) Const{return x*y.y-y.x*y;} Point operator/(double A) Const{return point (x/a,y/a);} Points[m],centre;struct line{double D1,d2,cross;line () {}line (double _,double __,double ___):d 1 (_), D2 (__), Cross (___/ _/__) {}bool operator = = (Const line &y) const;} A[m],b[m<<1];int N;bool Line:: operator = = (Const line &y) const{if (Fabs (D1-Y.D1) >eps) return false;if (fabs (D2-Y.D2) >eps) return false;if (Fabs (cross-y.cross) >eps) return False;return true; Double Distance (const point &p1,const point &p2) {return sqrt ((p1.x-p2.x) * (p1.x-p2.x) + (P1.Y-P2.Y) * (P1.Y-P2.Y));} int KMP (int len) {static int next[m];int i,fix=0,re=0;for (i=2;i<=n;i++) {while (fix &&!) A[fix+1]==a[i]) fix=next[fix];if (a[fix+1]==a[i]) ++fix;next[i]=fix; Fix=0;for (i=1;i<=len;i++) {while (fix &&!) ( A[fix+1]==b[i]) fix=next[fix];if (A[fix+1]==b[i]) ++fix;if (fix==n) ++re,fix=next[fix];} return re;} int main () {//freopen ("osi.in", "R", stdin),//freopen ("Osi.out", "w", stdout); int t;for (cin>>t; T t--) {int i;cin>>n;centre=point (0.0,0.0); for (i=1;i<=n;i++) points[i]. Read (),centre+=points[i]/static_cast<double> (n); for (i=1;i<=n;i++) b[i]=b[i+n]=line (Distance (points[i), Centre), Distance (Points[i%n+1],centre), (points[i]-centre) * (Points[i%n+1]-centre)); for (i=n;i;i--) A[n-i+1]=line ( b[i].d2,b[i].d1,0), A[N-I+1].CROSS=B[I].CROSS;COUT<<KMP (n+n-1) <<endl;}}
Bzoj 1100 POI2007 symmetry OSI computational geometry +KMP algorithm