https://codeforces.com/gym/101002
看了网上别人的代码怎么是n^3随便跑?
卧槽我还在这里猜想玄学复杂度会不会能过,然后加了一堆优化
去年网络赛有个只是关于中心点对称的原题
这题要考虑3种情况
1.关于中心点对称
2.关于垂直平分线对称且某些点就在垂直平分线上
3.很多点在一条直线上,自己和自己对称
第3种情况考场上没考虑就wa了。。。然后考虑到的时候只剩6分钟了比较紧张没改完。。。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxl=1e3+10;
int n,m,ans,cas,k,btot,ctot,cctot;
int dy[maxl*maxl];
struct node
{
ll x,y;
bool operator == (const node &b)const
{
return x==b.x && y==b.y;
}
}a[maxl];
struct nodenum
{
ll x,y;int num;
}b[maxl*maxl];
struct linenum
{
ll a,b,c;
bool operator == (const linenum &y)const
{
return a==y.a && b==y.b && c==y.c;
}
}c[maxl*maxl],cc[maxl*maxl];
char s[maxl];
bool in[maxl];
inline bool cmpb(const nodenum &x,const nodenum &y)
{
if(x.x==y.x)
return x.y<y.y;
return x.x<y.x;
}
inline void prework()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&a[i].x,&a[i].y);
a[i].x*=2;a[i].y*=2;
}
for(int i=1;i<=n;i++)
{
++btot;b[btot]={a[i].x,a[i].y,1};
for(int j=i+1;j<=n;j++)
{
++btot;
b[btot]={(a[i].x+a[j].x)/2,(a[i].y+a[j].y)/2,2};
}
}
sort(b+1,b+1+btot,cmpb);
ans=n;
int cnt=b[1].num;
for(int i=2;i<=btot;i++)
if(b[i].x==b[i-1].x && b[i].y==b[i-1].y)
cnt+=b[i].num;
else
{
ans=min(ans,n-cnt);
cnt=b[i].num;
}
ans=min(ans,n-cnt);
}
inline bool cmpc(const linenum &x,const linenum &y)
{
if(x.a==y.a)
{
if(x.b==y.b)
return x.c<y.c;
return x.b<y.b;
}
return x.a<y.a;
}
inline void mainwork()
{
if(n==1)
return;
linenum d;ll x2,y2,fz,fm,t;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
{
fz=(a[j].y-a[i].y);
fm=(a[j].x-a[i].x);
x2=(a[i].x+a[j].x)/2;
y2=(a[i].y+a[j].y)/2;
d.a=fm;d.b=fz;d.c=-(fz*y2+fm*x2);
t=__gcd(abs(d.a),abs(d.b));
t=__gcd(t,abs(d.c));
d.a/=t;d.b/=t;d.c/=t;
if(d.a==0)
{
if(d.b<0)
d.b=-d.b,d.c=-d.c;
}
else if(d.a<0)
d.a=-d.a,d.b=-d.b,d.c=-d.c;
c[++ctot]=d;
}
sort(c+1,c+1+ctot,cmpc);
int cnt=2;
for(register int i=2;i<=ctot;++i)
if(c[i]==c[i-1])
cnt+=2;
else
{
for(register int j=1;j<=n;++j)
if(c[i-1].a*a[j].x+c[i-1].b*a[j].y+c[i-1].c==0)
cnt++;
ans=min(ans,n-cnt);
cnt=2;
}
for(register int j=1;j<=n;++j)
if(c[ctot].a*a[j].x+c[ctot].b*a[j].y+c[ctot].c==0)
cnt++;
ans=min(ans,n-cnt);
for(int i=2;i<=n;i++)
dy[i*(i-1)/2]=i;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
{
fz=(a[j].y-a[i].y);
fm=(a[j].x-a[i].x);
d.a=fz,d.b=-fm,d.c=fm*a[i].y-fz*a[i].x;
t=__gcd(abs(d.a),abs(d.b));
t=__gcd(t,abs(d.c));
d.a/=t;d.b/=t;d.c/=t;
if(d.a==0)
{
if(d.b<0)
d.b=-d.b,d.c=-d.c;
}
else if(d.a<0)
d.a=-d.a,d.b=-d.b,d.c=-d.c;
cc[++cctot]=d;
}
sort(cc+1,cc+1+cctot,cmpc);
cnt=1;
for(register int i=2;i<=cctot;++i)
if(cc[i]==cc[i-1])
cnt++;
else
{
ans=min(ans,n-dy[cnt]);
cnt=1;
}
ans=min(ans,n-dy[cnt]);
}
inline void print()
{
printf("%d",ans);
}
int main()
{
int t=1;
//scanf("%d",&t);
for(cas=1;cas<=t;cas++)
{
prework();
mainwork();
print();
}
return 0;
}