POJ1006 Biorhythms【中国剩余定理】
<题目链接>
题目大意:
人体的体力每23天会达到峰值,情感每28天会达到峰值,智力每33天会达到峰值,一个人在a天体力达到峰值,b天情感达到峰值,c天智力达到峰值,求这个人下一次体力情感智力均达到峰值的天数减去d。
#include <iostream>
using namespace std;
int Extended_Euclid(int a,int b,int &x,int &y)
{
int d;
if(b==)
{
x=;y=;
return a;
}
d=Extended_Euclid(b,a%b,y,x);
y-=a/b*x;
return d;
}
int Chinese_Remainder(int a[],int w[],int num)
{
int i,d,x,y,m,lcm,ret;
ret=;
lcm=;
for (i=;i<num;i++)
lcm*=w[i];
for (i=;i<num;i++)
{
m=lcm/w[i];
d=Extended_Euclid(w[i],m,x,y);
ret=(ret+y*m*a[i])%lcm;
}
return (lcm+ret%lcm)%lcm;
} int main()
{
int n,i,c,d,C=,ans;
int w[]={,,},a[];
while (scanf("%d %d %d %d",&a[],&a[],&a[],&d)!=EOF)
{
if(a[]==-&&a[]==-&&a[]==-) break;
a[]%=;
a[]%=;
a[]%=;
int lcm=**;
ans=Chinese_Remainder(a,w,);
ans=ans-d;
if(ans<=) ans=ans+lcm;
printf("Case %d: the next triple peak occurs in %d days.\n", C++,ans);
} return ;
}
2018-07-31
POJ1006 Biorhythms【中国剩余定理】的更多相关文章
- POJ1006——Biorhythms(中国剩余定理)
Biorhythms Description人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这天,人会在相应的方面表现出色. ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 1006 Biorhythms --中国剩余定理(互质的)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103539 Accepted: 32012 Des ...
- POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...
- PKU POJ 1006 Biorhythms (中国剩余定理)
中国剩余定理 x = ai (mod mi) ai和mi是一组数,mi两两互质,求x 令Mi = m1*m2*~mk 其中,mi不包含在内. 因为mi两两互质,所以存在x和y, st M ...
- poj1006 / hdu1370 Biorhythms (中国剩余定理)
Biorhythms 题意:读入p,e,i,d 4个整数,已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i ,求n . (题在文末) 知识点:中国剩余定理 ...
- poj1006 中国剩余定理&&中国剩余定理解析
poj 1006 题的思路不是很难的,可以转化数学式: 现设 num 是下一个相同日子距离开始的天数 p,e,i,d 如题中所设! 那么就可以得到三个式子:( num + d ) % 23 == p: ...
- 【中国剩余定理】 poj 1006
生理周期 简单模拟 对于超出23 * 28 * 33(21252)时进行求余运算即可. #include<stdio.h> int main() { //freopen("in ...
- Biorhythms(poj1006+中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 117973 Accepted: 37026 Des ...
随机推荐
- tomcat顺序图摘要
1.Connector 处理一次请求顺序图 2.Context 和 wrapper 的处理请求时序图 3. 参考: https://www.ibm.com/developerworks/cn/java ...
- 以前的 Delphi版本
Delphi 1 Delphi 2 Delphi 3 Delphi 4 Delphi 5 Delphi 6 Delphi 7 Delphi 8 Delphi 2005
- VIM for C++ 一键安装配置
执行: wget https://raw.github.com/ma6174/vim/master/setup.sh -O ma6174_vim_setup.sh && bash ma ...
- 分布式系列 - dubbo服务telnet命令【转】
dubbo服务发布之后,我们可以利用telnet命令进行调试.管理.Dubbo2.0.5以上版本服务提供端口支持telnet命令,下面我以通过实例抛砖引玉一下: 1.连接服务 测试对应IP和端口下的d ...
- python3爬虫中文乱码之请求头‘Accept-Encoding’:br 的问题
当用python3做爬虫的时候,一些网站为了防爬虫会设置一些检查机制,这时我们就需要添加请求头,伪装成浏览器正常访问. header的内容在浏览器的开发者工具中便可看到,将这些信息添加到我们的爬虫代码 ...
- 编写html与js交互网页心得:编写两个按钮切换显示不同的图片
第一步:先建立一个html网页,如下: <!DOCTYPE html><html> <head> <meta charset="utf-8&quo ...
- Android GsmCellLocation.getCellLocation返回NULL
Android GsmCellLocation.getCellLocation返回NULL 1.首先 获取服务 telephonyManager =(TelephonyManager)getSyste ...
- 使用 ButterKnife 操作无效(不报错、点击后没效果)------代码编写错误
错误写法 ButterKnife.bind(this, inflater.inflate(R.layout.buju, container, false)); return inflater.infl ...
- 关卡得分(if 嵌套for)与(for嵌套if)
- raindi python魔法函数(一)之__repr__与__str__
__repr__和__str__都是python中的特殊方法,都是用来输出实例对象的,如果没有定义这两个方法在打印的时候只会输出实例所在的内存地址 这种方式的输出没有可读性,并不能直观的体现实例.py ...