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 ...
随机推荐
- MySQL自动设置create_time和update_time
参考表结构 CREATE TABLE `t_baby` ( `baby_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, ...
- python - 添加文件环境变量
#添加 当前文件目录 import sys,os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) sys.path.append(BASE ...
- DropEditText
https://blog.csdn.net/jdsjlzx/article/details/46860563 https://github.com/qibin0506/DropEditText ...
- Android ROM资源文件存放位置
位于目录:framework/core/res/res /frameworks/base/core/res/res/values/public.xml 上面的文件中公开了上层(也就是第三方应用或者系统 ...
- android aysncTask面试解析
- concurrent.futures- 启动并行任务
python因为其全局解释器锁GIL而无法通过线程实现真正的平行计算.这个论断我们不展开,但是有个概念我们要说明,IO密集型 vs. 计算密集型. IO密集型:读取文件,读取网络套接字频繁. 计算密集 ...
- iOS8中 UILocalNotification 和 UIRemoteNotification 使用注意
先说一个关于UILocalNotification的知识点,容易被忘记: Each app on a device is limited to 64 scheduled local notificat ...
- Java基础98 gson插件的使用
1.要用到的包 2.实例 实体类 people package com.shore.entity; /** * @author DSHORE/2019-4-21 * */ public class P ...
- webpack 3之hash、chunkhash和contenthash三者的区别
在使用webpack 3中,文件名的hash值可以有三种hash生成方式,那具体使用哪一种呢? 1.hash 如果都使用hash的话,所有文件的hash都是一样的,而且每次修改任何一个文件,所有文件名 ...
- windows下sublime通过sftp扩展上传文件到linux服务器上
首先在package controll下载sftp扩展,在任意磁盘下新建文件夹: 然后,添加该文件夹到sublime中,并在xhell中链接linux服务器,新建目录,mkdir /home/hel ...