POJ 1006 Biorhythms --中国剩余定理(互质的)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 103539 | Accepted: 32012 |
Description
Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.
Input
Output
Case 1: the next triple peak occurs in 1234 days.
Use the plural form ``days'' even if the answer is 1.
Sample Input
0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1
Sample Output
Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.
Source
/*
纯中国剩余定理。 */ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; __int64 a[];
__int64 m[]={,,,};
__int64 tom; __int64 Ex_gcd(__int64 a,__int64 b,__int64 &x,__int64 &y)
{
if(b==)
{
x=;
y=;
return a;
}
__int64 g=Ex_gcd(b,a%b,x,y);
__int64 hxl=x-(a/b)*y;
x=y;
y=hxl;
return g;
} __int64 china()
{
__int64 i,x,y,mi,hxl=,sum=,d; for(i=;i<=;i++)
sum=sum*m[i];
for(i=;i<=;i++)
{
mi=sum/m[i];
d=Ex_gcd(m[i],mi,x,y);
hxl=(hxl+mi*y*a[i])%sum;
}
hxl=hxl-tom;
if(hxl>)
return hxl;
else
return hxl+;
} void make_ini(__int64 t)
{
__int64 k;
k=china();
printf("Case %I64d: the next triple peak occurs in %I64d days.\n",t++,k);
} int main()
{
__int64 sb,p,e,i,t=;
// scanf("%I64d",&sb);
while(scanf("%I64d%I64d%I64d%I64d",&p,&e,&i,&tom)>)
{
if(p==- && e==- && i==- &&tom==-)break;
a[]=p;a[]=e;a[]=i;
make_ini(++t);
}
return ;
}
POJ 1006 Biorhythms --中国剩余定理(互质的)的更多相关文章
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- 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 ...
- 模板-->中国剩余定理[互质版本]
如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 扩展欧几里得extend_gcd模板 poj_1006_Biorhythms,my_ac_code 简单的测试 None ...
- POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)
POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
- POJ 1006 Biorhythms (中国剩余定理)
在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
随机推荐
- 设置、读取、删除cookie
刚才用虚拟机当服务器,开了两个服务(端口号不同),发现同样的cookie:在别的网站下面没有发现该cookie.说明cookie只是对应相应的网站的(自己得出的结论) ---------------- ...
- elasticsearch5.2.1使用logstash同步mysql
centos 本人亲测可以 首先安装好mysql,elasticsearch 不懂的请参考另一篇文章 安装logstash官方:https://www.elastic.co/guide/en/l ...
- mysql5.7.20多实例编译安装
好记性不如烂笔头! MySQL多实例 实际上就是在同一台服务器上运行多个mysql服务进程. 相同点:公用同一套MySQL安装程序. 不同点:使用不同的配置文件(也可以相同).启动程序(也可以相同). ...
- 2016级算法期末上机-A.简单·Bamboo's Fight with DDLs I
简单·Bamboo's Fight with DDLs I 分析 一句话:要装满的完全背包问题. 对比完全背包只有一点要改变:初始化为负无穷 传送门: https://buaacoding.cn/pr ...
- Google Spanner vs Amazon Aurora: Who’ll Get the Enterprise?
https://www.clustrix.com/bettersql/spanner-vs-aurora/ Google Spanner versus Amazon Aurora In July 20 ...
- .crx 文件修改
.crx 文件类型:Chrome Extension 扩展名为.crx的文件是一个插件文件. 解压:使用7zip 修改: notepad++ 打包: Chrome 扩展项
- Spring事务杂谈
1. 什么是事务 事务就是以一种可控的方式,对资源进行的一组操作,保证了资源在事务前后,始终应处于被期待的正确的状态.比如不会受到宕机等原因的影响.事务本身,具有如下4种属性-ACID.(所以说事务是 ...
- 关于function构造函数特别注意的
function在javascript中是对象,所以function持有构造函数例子:var a = new Function("x","y","re ...
- 在Linux上创建webrev[基于git]
在Sun/Oracle工作了N(>12)年后,对webrev工具甚为喜欢,因为其易用性确实非常好.幸运的是,有工程师将webrev工具放到了GitHub上,而且支持git. 下面给出使用webr ...
- 12 Callable & Future & FutureTask
创建线程的2种方式,一种是直接继承Thread,另外一种就是实现Runnable接口. 这2种方式都有一个缺陷就是:在执行完任务之后无法获取执行结果. 如果需要获取执行结果,就必须通过共享变量或者使用 ...