Biorhythms(poj1006+中国剩余定理)
Biorhythms
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 117973 | Accepted: 37026 |
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
题意:
生理周期
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 117973 | Accepted: 37026 |
Description
Input
当p = e = i = d = -1时,输入数据结束。
Output
采用以下格式:
Case 1: the next triple peak occurs in 1234 days.
注意:即使结果是1天,也使用复数形式“days”。
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
Translator
解法:中国剩余定理,看了很多的博客终于总结了自己的模板,也是我入门题了。
关于中国剩余定理的解释: http://www.cnblogs.com/yuyixingkong/p/4358300.html 与 http://baike.sogou.com/v1853008.htm 与 http://www.cnblogs.com/tom987690183/p/3260625.html 与 http://blog.csdn.net/u010468553/article/details/38346195 都可以作为参考的博客;
关于欧几里得和逆元的解释:http://blog.csdn.net/cqlf__/article/details/7953039 与 http://blog.csdn.net/acdreamers/article/details/8220787 都可以作为参考的博客;
转载请注明出处:寻找&星空の孩子
题目链接:poj1006
#include<stdio.h>
#define LL __int64
LL m[]={,,};
LL at[];
LL s;
void exgcd(LL a,LL b,LL &d,LL &x,LL &y)
{
if(b==)
{
x=;
y=;
d=a;
return ;
}
else
{
exgcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}
LL China(int r)
{
LL Mc=;
LL i,Mi,x,y,d,as=;
for(i=; i<r; i++)
Mc*=m[i];
for(i=; i<r; i++)
{
Mi=Mc/m[i];
exgcd(Mi,m[i],d,x,y);
as=(as+Mi*x*at[i])%Mc;
}
as-=s;
if(as<=)
as+=Mc;
return as;
}
LL work()
{
if(!(at[]%m[]||at[]%m[]||at[]%m[]))
return **-s;
else
China();
}
int main()
{
int test=;
while(scanf("%I64d%I64d%I64d%I64d",&at[],&at[],&at[],&s)!=EOF)
{
if(at[]==-&&at[]==-&&at[]==-&&s==-) break;
printf("Case %d: the next triple peak occurs in %I64d days.\n",test++,work());
}
return ;
}
Biorhythms(poj1006+中国剩余定理)的更多相关文章
- POJ1006: 中国剩余定理的完美演绎
POJ1006: 中国剩余定理的完美演绎 问题描述 人自出生起就有体力,情感和智力三个生理周期,分别为23,28和33天.一个周期内有一天为峰值,在这一天,人在对应的方面(体力,情感或智力)表现最 ...
- POJ1006 - Biorhythms(中国剩余定理)
题目大意 略...有中文... 题解 就是解同余方程组 x≡(p-d)(mod 23) x≡(e-d)(mod 28) x≡(i-d)(mod 33) 最简单的中国剩余定理应用.... 代码: #in ...
- [转]POJ1006: 中国剩余定理的完美演绎
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 117973 Accepted: 37026 Des ...
- Biorhythms(中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127339 Accepted: 40342 Des ...
- poj1006 中国剩余定理&&中国剩余定理解析
poj 1006 题的思路不是很难的,可以转化数学式: 现设 num 是下一个相同日子距离开始的天数 p,e,i,d 如题中所设! 那么就可以得到三个式子:( num + d ) % 23 == p: ...
- POJ 1006 Biorhythms (中国剩余定理)
在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...
- POJ1006: 中国剩余定理的完美演绎(非原创)
问题描述 人自出生起就有体力,情感和智力三个生理周期,分别为23,28和33天.一个周期内有一天为峰值,在这一天,人在对应的方面(体力,情感或智力)表现最好.通常这三个周期的峰值不会是同一天.现在给出 ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- 【题解】UVA756 Biorhythms (中国剩余定理)
UVA756:https://www.luogu.org/problemnew/show/UVA756 思路 几乎是裸的中国剩余定理模板题 但是需要注意的是此题并不是求最小正整数解 而是求大于d的解 ...
随机推荐
- OpenLayer实现路径运动
近期由于业务的需求,让我这从未想过要碰Web Gis的业余前端开发者,走了Web Gis的开发道路.功能需求很简单,但却也是让自己难为了好几天.如,应该选择那个Gis框架,Gis框架的兼容性如何,直接 ...
- vue防止按钮在短时间内被多次点击的方法
vue组件 (function(){ let openDelay=false; Vue.directive('intervalclick', function(el,binding){ el.oncl ...
- Hi,给他介绍一款markdown的帮助文档生成器
当今大多数的团队都实现了前.后端分支.前端与后端的沟通都是通过接口来实现的(一般情况下都是webapi接口).这种情况你肯定需要一个接口查询的帮助文档,这个当然用swagger都可以实现.但做为前端开 ...
- [Inside HotSpot] C1编译器优化:全局值编号(GVN)
1. 值编号 我们知道C1内部使用的是一种图结构的HIR,它由基本块构成一个图,然后每个基本块里面是SSA形式的指令,关于这点如可以参考[Inside HotSpot] C1编译器工作流程及中间表示. ...
- mybatis小结
mybatis是Apache的一个开源项目ibatis,后由Google管理,目前在github上.MyBatis 是支持定制化SQL.存储过程以及高级映射的优秀的持久层框架. 一.mybatis解决 ...
- Java 在PDF文档中绘制图形
本篇文档将介绍通过Java编程在PDF文档中绘制图形的方法.包括绘制矩形.椭圆形.不规则多边形.线条.弧线.曲线.扇形等等.针对方法中提供的思路,也可以自行变换图形设计思路,如菱形.梯形或者组合图形等 ...
- U盘制作微pe工具箱(实战)
分享人:广州华软 浩言 前言 相信大家平时生活中还是工作上使用电脑的时间还是比较多的,有时候电脑出现故障,比如系统文件损坏,没办法正常开机,或者是开机密码忘了,想要重装系统等,下面我推荐一个U盘启动项 ...
- SQL Server作业报错特殊案例
一个作业报错,报错信息如下,从错误信息根本看不出为什么出错,手工运行作业又成功了.一时不清楚什么原因导致作业出错. Message Executed as user: NT SERVICE\SQLSE ...
- kafka 幂等生产者及事务(kafka0.11之后版本新特性)
1. 幂等性设计1.1 引入目的生产者重复生产消息.生产者进行retry会产生重试时,会重复产生消息.有了幂等性之后,在进行retry重试时,只会生成一个消息. 1.2 幂等性实现1.2.1 PID ...
- Spring Bean 生命周期测试
本文代码GitHub地址 Bean的生命周期是开始创建到销毁的过程.需要实现相关的类BeanNameAware ,DisposableBean, InitializingBean ,并注册Inst ...