zoukankan      html  css  js  c++  java
  • HHHOJ #153. 「NOI模拟 #2」Kotomi

    抽代的成分远远大于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
    ",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;
    }
    
  • 相关阅读:
    JavaScript数组方法
    模拟js数组indexOf方法
    js数组排序
    发布Exchange的SMTP,POP3服务器:ISA2006系列之十八
    用智能卡构建身份验证的马其诺防线:ISA2006系列之二十三
    Java与CSharp的相同与不同
    创建可传递的林信任,Active Directory系列之二十
    组策略指派Office2003分发,Active Directory系列之二十三
    发布Exchange的RPC以及RPC Over HTTPS:ISA2006系列之十九
    初步理解组策略,Active Directory系列之二十一
  • 原文地址:https://www.cnblogs.com/cjjsb/p/12080986.html
Copyright © 2011-2022 走看看