抽代的成分远远大于OI的成分
首先把一个点定为原点,然后我们发现如果我们不旋转此时答案就是所有位置的\(\gcd\)
如果要选择怎么办,我们考虑把我们选定的网格边连同方向和大小看做单位向量\(\vec e\)
那么此时我们把坐标系变成复平面,每个点都可以表示成\((a+bi)\vec e\)的形式
当\(a,b\)均为整数时,它其实是个高斯整数的形式,那么我们可以把带余除法推广到高斯整数环
一些具体的姿势详见:高斯整数余数的一个问题
然后直接推广出辗转相除即可,利用不等式放缩容易得出此时一定是最优的
#include<cstdio>
#include<iostream>
#define int long long
#define RI register int
#define CI const int&
using namespace std;
const int N=100005;
inline int Fix(int x,int y)
{
int f=1; if (x<0) x=-x,f=-1; return (x%y*2<y)?((x/y)*f):((x/y+1)*f);
}
struct Complex
{
int x,y;
inline Complex(CI X=0,CI Y=0)
{
x=X; y=Y;
}
friend inline Complex operator + (const Complex& A,const Complex& B)
{
return Complex(A.x+B.x,A.y+B.y);
}
friend inline Complex operator - (const Complex& A,const Complex& B)
{
return Complex(A.x-B.x,A.y-B.y);
}
friend inline Complex operator * (const Complex& A,const Complex& B)
{
return Complex(A.x*B.x-A.y*B.y,A.y*B.x+A.x*B.y);
}
friend inline Complex operator / (const Complex& A,const Complex& B)
{
Complex iB=Complex(B.x,-B.y),ret=A*iB; int dv=B.x*B.x+B.y*B.y;
return Complex(Fix(ret.x,dv),Fix(ret.y,dv));
}
friend inline Complex operator % (const Complex& A,const Complex& B)
{
return A-((A/B)*B);
}
}a[N],g; int n,mix,mxx,miy,mxy;
inline Complex gcd(const Complex& A,const Complex& B)
{
//printf("%lld %lld %lld %lld\n",A.x,A.y,B.x,B.y);
if (!B.x&&!B.y) return A; return gcd(B,A%B);
}
signed main()
{
RI i; for (scanf("%lld",&n),i=1;i<=n;++i) scanf("%lld%lld",&a[i].x,&a[i].y);
for (i=2;i<=n;++i) a[i]=a[i]-a[1]; for (g=a[2],i=3;i<=n;++i) g=gcd(g,a[i]);
for (i=2;i<=n;++i) a[i]=a[i]/g,mix=min(mix,a[i].x),mxx=max(mxx,a[i].x),
miy=min(miy,a[i].y),mxy=max(mxy,a[i].y); return printf("%lld",max(mxx-mix,mxy-miy)),0;
}