B - Biorhythms——(中国剩余定理)
来源:互联网 发布:淘宝app五星评价 编辑:程序博客网 时间:2024/06/05 10:28
传送门
Password:nefu
题目大意:都是中文。。。
解题思路:
根据题意,我们可以分析得到如下几个等式:
(n+d)%23=p;(n+d)%28=e;
(n+d)%33=i;
上述的 n 为下一次三个高峰同天的时间
因为23,28 和 33 都是两两互素的所以就更简单了,m = 23 * 33 * 28 = 21252;所以 这就让我们想到了中国剩余定理,只需要扩展欧几里得搞一下就好了(中国剩余定理还是离散的时候学的呢。。。。),注意当 n == 0 的时候我们要输出的是21252,基本上就可以写代码了.
My Code:
#include <iostream>#include <cstdio>using namespace std;///(n+d)%23=p; (n+d)%28=e; (n+d)%33=ivoid exgcd(int a, int b, int &x, int &y){ if(b == 0) { x = 1; y = 0; return; } int x1, y1; exgcd(b, a%b, x1, y1); x = y1; y = x1 - (a/b)*y1;}int main(){ int d, p, e, i, cas = 1; while(cin>>p>>e>>i>>d) { if(p < 0) break; int m = 21252; int M1 = 924; int M2 = 759; int M3 = 644; int x1, x2, x3, y; exgcd(M1, 23, x1, y); x1 = (x1%23+23)%23; exgcd(M2, 28, x2, y); x2 = (x2%28+28)%28; exgcd(M3, 33, x3, y); x3 = (x3%33+33)%33; int ans = ((p*M1*x1+e*M2*x2+i*M3*x3-d)%m+m)%m; if(ans == 0) ans = m; printf("Case %d: the next triple peak occurs in %d days.\n",cas++,ans); } return 0;}
0 0
- B - Biorhythms——(中国剩余定理)
- Biorhythms——中国剩余定理
- 中国剩余定理题——Biorhythms
- 中国剩余定理(CRT 孙子定理)——Biorhythms(POJ 1006)
- POJ 1006 ——Biorhythms 中国剩余定理模板
- 北大ACM1006——Biorhythms~~中国剩余定理
- poj 1006 Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms (中国剩余定理)
- Biorhythms(中国剩余定理的应用)
- POJ - 1006 Biorhythms (中国剩余定理)
- POJ-1006-Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms (中国剩余定理)
- poj 1006 Biorhythms(中国剩余定理)
- Biorhythms(poj1006+中国剩余定理)
- 半同步/半异步体系结构模式
- 典型递归问题--爬楼梯
- 一个GIS专业java实习生的日记——上班第一天
- 欢迎使用CSDN-markdown编辑器
- PAT 结尾
- B - Biorhythms——(中国剩余定理)
- 欢迎来访个人网站——阳光日志
- UVaOJ_Problem10361_Automatic Poetry
- Android RSA加密解密的 工具类的使用
- mysql错误2002的解决办法 ERROR 2002 (HY000) mysql.sock(2)
- 【HDU2602】Bone Collector(01背包入门级)
- javascript
- 今天就开始写写博客了
- Spring与策略模式