隐藏页面特效

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; }

__EOF__

本文作者hl666
本文链接https://www.cnblogs.com/cjjsb/p/12080986.html
关于博主:复活的ACM新生,目前爱好仅剩Gal/HBR/雀魂/单机/OSU
版权声明:转载请注明出处
声援博主:欢迎加QQ:2649020702来DD我
posted @   空気力学の詩  阅读(290)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
阅读排行:
· 物流快递公司核心技术能力-海量大数据处理技术
· 几个技巧,教你去除文章的 AI 味!
· 系统高可用的 10 条军规
· 如何在 Github 上获得 1000 star?
· 关于普通程序员该如何参与AI学习的三个建议以及自己的实践
历史上的今天:
2017-12-22 Luogu P1082 同余方程
2017-12-22 EZ 2017 12 17初二初三第一次膜你赛
点击右上角即可分享
微信分享提示