POJ 1006-Biorhythms,中国剩余定理,学信安的路过!
来源:互联网 发布:unity3d跑酷游戏素材 编辑:程序博客网 时间:2024/06/05 05:43
Biorhythms
我竟然1A了, 终于从一天的浑噩中找回点自信了。人生第一次做中国剩余定理的题,靠着自己的理解。
题意:人的一生分别有体力,情感,智商三个生理周期巅峰,循环时间分别是23,28,33天。现在给出你这三个生理活动在今年出现巅峰的时期(不一定是今年的第一次巅峰状态),然后给出今天的日期,求下一次同时达到巅峰距今天有多少天,如果今天就是同时达到巅峰那么需要求出下一次巅峰。
思路:如果会扩展欧几里德算法就很简单了。很明显是中国剩余定理的一个运用。分别用两个数组存模数和这三个生理日期,然后利用公式:M1*M11*b1+M2*M22*b2+M3*M33*b3+...+Mi*Mii*bi。这里Mii是Mi关于模mi的乘法逆元。
ll e_gcd(ll a,ll b,ll &x,ll &y){ if(a==0&&b==0) return -1; if(b==0) { x=1,y=0; return a; } ll d=e_gcd(b,a%b,y,x); y-=a/b*x; return d;}int main(){ ll b[3],d; ll m[3]={23,28,33}; int t=1; while(~scanf("%I64d%I64d%I64d%I64d",&b[0],&b[1],&b[2],&d)) { if(d==-1) return 0; b[0]=b[0]?b[0]:23; b[1]=b[1]?b[1]:28; b[2]=b[2]?b[2]:33; ll M=21252; ll ans=0; for(int i=0;i<3;i++) { ll x,y; ll mi=M/m[i]; ll k=e_gcd(mi,m[i],x,y); ans=(ans+M+mi*x*b[i])%M; } ans=ans<=d?ans+M:ans; printf("Case %d: the next triple peak occurs in %I64d days.\n",t++,ans-d); } return 0;}
0 0
- POJ 1006-Biorhythms,中国剩余定理,学信安的路过!
- poj 1006 Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms(中国剩余定理)
- poj 1006 Biorhythms 中国剩余定理
- POJ 1006 Biorhythms 中国剩余定理
- POJ 1006 Biorhythms 中国剩余定理
- POJ 1006 Biorhythms (中国剩余定理)
- POJ 1006 Biorhythms 中国剩余定理
- poj 1006 Biorhythms 中国剩余定理
- Biorhythms(poj 1006)(中国剩余定理)
- POJ 1006 Biorhythms 中国剩余定理
- POJ 1006---Biorhythms【中国剩余定理】
- poj 1006 Biorhythms 中国剩余定理
- POJ - 1006 Biorhythms (中国剩余定理)
- POJ 1006 Biorhythms 【中国剩余定理】
- POJ-1006-Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms(中国剩余定理)
- cocos2dx-lua中实现面向对象的封装继承
- php 接口写法
- 数据恢复:在 Linux 上恢复删除了的文件
- 2016年CSDN十大博客之星评选,快来投票哈~
- powergui _matlab/simulink
- POJ 1006-Biorhythms,中国剩余定理,学信安的路过!
- 浅探RecyclerView的removeItem操作
- 关于UIScrollView中UIImageView的图片缩放问题
- ubuntu的更新错误-在源列表 /etc/apt/sources.list.d/google-chrome.list 中第 1 行有误 (类型)
- 3-7 类的友元函数的应用
- Redis Sentinel(redis哨兵)介绍
- 异军突起的宽松开源许可证
- Servlet开发步骤
- POJ 1598 Excuses, Excuses! 已被翻译