POJ 1006 Biorhythms
来源:互联网 发布:手机自动充电软件 编辑:程序博客网 时间:2024/04/29 08:11
POJ 1006 Biorhythms
首先我们要知道,任意两个峰值之间一定相距整数倍的周期。假设一年的第N天达到峰值,则下次达到峰值的时间为N+Tk(T是周期,k是任意正整数)。所以,三个峰值同时出现的那一天(S)应满足
可以考虑从结果逆推。根据上面的等式,S满足三个要求:除以T1余数为N1,除以T2余数为N2,除以T3余数为N3。这样我们就把问题转化为求一个最小数,该数除以T1余N1,除以T2余N2,除以T3余N3。这就是中国剩余定理。依据此,时间复杂度可达到O(1)。
#include<cstdio> const int P=21252;int p,e,i,d,n,count=0;int main(){ while(scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF) { count++; if(p==-1&&e==-1&&i==-1&&d==-1) { break; } n=(5544*p+14421*e+1288*i-d)%P; if(n<=0) { n+=21252; } printf("Case %d: the next triple peak occurs in %d days.\n",count,n); } 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
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 Biorhythms
- POJ 1006 Biorhythms
- Poj 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 hdu1370 Biorhythms
- 【POJ】1006 Biorhythms
- poj 1006 Biorhythms
- Hbase的热点问题
- 知趣
- angular自定义过滤器模糊查询
- 何谓保存现场 SetJump & LongJump 解读
- 番外:如何给github上的开源项目贡献代码?
- POJ 1006 Biorhythms
- Android.Application
- Navicat连接阿里云Ubuntu的mysql
- 欢迎使用CSDN-markdown编辑器
- 写给立志做码农的大学生
- java8 新特性
- leetcode 405. Convert a Number to Hexadecimal 十进制转化十六进制
- nginx 公用一个tomcat,配置不同的域名
- 女博士养成记2——挣钱养梦