传送门
这道题要将图形转化为字符串,可以发现,只要角相同,边长相同就存在一条对称轴,所以只要转换成字符串S,倍长为SS,拿反串匹配一下就好了。
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=1e5+10;
int T,n,nxt[maxn*2],ans;double f[maxn*4],a[maxn*2];
struct oo{double x,y;}s[maxn];
double dis(oo a,oo b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
double make(oo a,oo b,oo c){return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}
int main()
{
read(T);
while(T--)
{
read(n),ans=0;
for(rg int i=0;i<n;i++)scanf("%lf%lf",&s[i].x,&s[i].y);
for(rg int i=0;i<n;i++)f[(i+1)*2]=f[(i+1)*2+n*2]=dis(s[i],s[(i+1)%n]);
for(rg int i=0;i<n;i++)f[(i+1)*2-1]=f[(i+1)*2-1+n*2]=make(s[(i-1+n)%n],s[i],s[(i+1)%n]);
for(rg int i=1;i<=n*2;i++)a[n*2-i+1]=f[i];
for(rg int i=2,j=0;i<=n*2;i++)
{
while(j&&a[j+1]!=a[i])j=nxt[j];
if(a[j+1]==a[i])j++;
nxt[i]=j;
}
for(rg int i=1,j=0;i<=n*4;i++)
{
while(j&&a[j+1]!=f[i])j=nxt[j];
if(a[j+1]==f[i])j++;
if(j==n*2)ans++;
}
printf("%d
",ans);
}
}