HHHOJ #153. 「NOI模拟 #2」Kotomi

抽代的成分远远大于OI的成分

首先把一个点定为原点,然后我们发现如果我们不旋转此时答案就是所有位置的gcd

如果要旋转怎么办,我们考虑把我们选定的网格边连同方向和大小看做单位向量e

那么此时我们把坐标系变成复平面,每个点都可以表示成(a+bi)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;
}
posted @   空気力学の詩  阅读(287)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何调试 malloc 的底层源码
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
阅读排行:
· Apifox不支持离线,Apipost可以!
· 零经验选手,Compose 一天开发一款小游戏!
· Trae 开发工具与使用技巧
· 历时 8 年,我冲上开源榜前 8 了!
· 通过 API 将Deepseek响应流式内容输出到前端
历史上的今天:
2017-12-22 Luogu P1082 同余方程
2017-12-22 EZ 2017 12 17初二初三第一次膜你赛
点击右上角即可分享
微信分享提示