BZOJ 1407 exgcd
来源:互联网 发布:佳能ip1180清零软件 编辑:程序博客网 时间:2024/05/20 19:50
枚举 山洞个数,每次n^2 枚举两个野人之间是否会发生冲突.
相当于求p[i]*x+c[i] = p[j]*x+c[j] mod m (天数)
----------> (p[i]-p[j])*x-m*y = c[j]-c[i] .. exgcd 求解.
#include <iostream>#include <cstring>#include <algorithm>#include <stdio.h>#define MAXN 17using std::max;int n,p[MAXN],c[MAXN],l[MAXN],mx; template<typename _t>inline _t read(){ _t x=0,f=1; char ch=getchar(); for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-')f=-f; for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+(ch^48); return x*f;} inline int gcd(int x,int y){return y==0?x:gcd(y,x%y);} void gcd(int a,int b,int &x,int &y){if(b==0){x=1;y=0;return;}gcd(b,a%b,x,y);int t=x;x=y;y=t-a/b*y;} inline bool Judge(int tot){ // (p[i]-p[j])*x -my = c[j]-c[i]; for(register int i=1;i<=n;i++){ for(register int j=i+1;j<=n;j++){ int A,B,C,x,y; A = p[i]-p[j],B=c[j]-c[i],C=tot; int t = gcd(A,C); if(B%t==0){ A/=t;B/=t;C/=t; gcd(A,C,x,y); if(C<0)C=-C; x = ((B*x)%C+C)%C; if(!x)x+=C; if(x<=l[i]&&x<=l[j])return 0; } } } return 1;} int main(){ n=read<int>(); for(int i=1;i<=n;i++){ c[i]=read<int>(), p[i]=read<int>(), l[i]=read<int>(); mx=max(mx,c[i]); } while(!Judge(mx++));mx--; printf("%d\n",mx);}
阅读全文
0 0
- bzoj 1407 exgcd
- BZOJ 1407 exgcd
- bzoj 1477 exgcd
- BZOJ 4522 Pollard-rho+exgcd
- Bzoj 3122 [Sdoi2013]随机数生成器(BSGS+exgcd)
- exgcd
- Exgcd
- exgcd
- exgcd
- EXGCD
- BZOJ 2242 [SDOI2011]计算器 BSGS+快速幂+EXGCD
- bzoj 1420&&bzoj 1319: Discrete Root 原根+BSGS+exgcd+模线性方程
- bzoj 2142: 礼物(组合数取模终极版) 组合数学+中国剩余定理+exgcd
- exgcd求逆元
- gcd&exgcd
- poj1061-exgcd
- exgcd解系
- vijos 1009(exgcd)
- 使用反射机制完成学生对象的创建并输出学生信息。
- 1104: 盒子游戏(简单博弈)
- CSS基础知识
- 网易2018校招在线编程题-第二题
- Cake HDU
- BZOJ 1407 exgcd
- 设计模式笔记--设计模式比较
- RecycleView的刷新,点击监听以及下划线设置
- netkit-ng安装使用
- SqlServer2005在win7系统64位上卸载重装
- 高精度-小数加法【模板】
- $.each()和$().each(),以及 forEach ()的用法
- 【编程练习】单链表逆序Java实现
- django中的用户认证