Biorhythms
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 110991   Accepted: 34541

Description

Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier. 
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

You will be given a number of cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional, and intellectual cycles peak, respectively. The value d is the given date and may be smaller than any of p, e, or i. All values are non-negative and at most 365, and you may assume that a triple peak will occur within 21252 days of the given date. The end of input is indicated by a line in which p = e = i = d = -1.

Output

For each test case, print the case number followed by a message indicating the number of days to the next triple peak, in the form:

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

  
  水题,中国剩余定理,经典题
  题意
  人自出生起就有体力,情感和智力三个生理周期,分别为23,28和33天。一个周期内有一天为峰值,在这一天,人在对应的方面(体力,情感或智力)表现最好。通常这三个周期的峰值不会是同一天。现在给出三个日期,分别对应于体力,情感,智力出现峰值的日期。然后再给出一个起始日期,要求从这一天开始,算出最少再过多少天后三个峰值同时出现。
  思路
  这道题需要用到中国剩余定理,中国剩余定理,也称孙子定理。这里有一个经典问题:
《孙子算经》中的题目:有物不知其数,三个一数余二,五个一数余三,七个一数又余二,问该物总数几何?
  意思就是有一个数除以3余2,除以5余3,除以7余2,问这个数是多少。
  而孙子定理(中国剩余定理)就是求解这个问题的方法。
  再看这道题,你要求多少天之后,出现三重峰,即要求的天数da要求加上开始的天数d除以三个生理周期23,28,33都是整除。我们将da+d看成一个数n,即n%k1=0,n%k2=0,n%k3=0。那么我们只要把n求出来,就能求出da(d已知)。
  这样直接套用中国剩余定理的解法即可。
  详细的过程就不写了,可以猛戳右方链接,说的很详细:POJ1006-Biorhythms
  对中国剩余定理还不是很懂的可以见百度百科的介绍,写的不错:中国剩余定理 - 百度百科
  代码
 #include <iostream>

 using namespace std;
int main()
{
int p,e,i,d,Case=;
while(cin>>p>>e>>i>>d){
if(p==- && e==- && i==- && d==-) break;
int da = (*p+*e+*i-d+)%;
if(da==)
cout<<"Case "<<Case++<<": the next triple peak occurs in 21252 days."<<endl;
else
cout<<"Case "<<Case++<<": the next triple peak occurs in "
<<da<<" days."<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

poj 1006:Biorhythms(水题,经典题,中国剩余定理)的更多相关文章

  1. POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)

    POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...

  2. Educational Codeforces Round 12补题 经典题 再次爆零

    发生了好多事情 再加上昨晚教育场的爆零 ..真的烦 题目链接 A题经典题 这个题我一开始推公式wa 其实一看到数据范围 就算遍历也OK 存在的问题进制错误 .. 思路不清晰 两个线段有交叉 并不是端点 ...

  3. POJ 1006 - Biorhythms (中国剩余定理)

    B - Biorhythms Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Subm ...

  4. POJ 1006 Biorhythms --中国剩余定理(互质的)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103539   Accepted: 32012 Des ...

  5. 中国剩余定理 POJ 1006 Biorhythms

    题目传送门 题意:POJ有中文题面 分析:其实就是求一次同余方程组:(n+d)=p(%23), (n+d)=e(%28), (n+d)=i(%33),套用中国剩余定理模板 代码: /********* ...

  6. POJ 1006 Biorhythms(中国剩余定理)

    题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...

  7. poj 1006 Biorhythms (中国剩余定理模板)

    http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...

  8. POJ 1006 Biorhythms (中国剩余定理)

    在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...

  9. POJ 1006 Biorhythms (数论-中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 111285   Accepted: 34638 Des ...

随机推荐

  1. Mysql5.7版本编译安装及配置

    配置yum安装方式 1.配置本地yum源 vim /etc/yum.repos.d/rhel-source.repo [rhel-source] name=Red Hat Enterprise Lin ...

  2. java.lang.ClassNotFoundException: net.sf.json.JSONArray,java.lang.NoClassDefFoundError: net/sf/json/JSONArray jetty跑项目遇到的问题

    2016-05-18 15:44:25 ERROR Dispatcher.error[user:|url:]:L38 - Dispatcher initialization failed Unable ...

  3. Tomcat配置文件server.xml详解

    <?xml version='1.0' encoding='utf-8'?> <Server port="8005" shutdown="SHUTDOW ...

  4. POI文件导出至EXCEL,并弹出下载框

    相关参考帖子 : [1]http://www.tuicool.com/articles/MnqeUr [2]http://www.oschina.net/question/253469_51638?f ...

  5. 解读Unity中的CG编写Shader系列六(漫反射)

    转自 http://www.itnose.net/detail/6116553.html 如果前面几个系列文章的内容过于冗长缺乏趣味着实见谅,由于时间原因前面的混合部分还没有写完,等以后再补充,现在开 ...

  6. linux学习之lvm-逻辑卷管理器

    一.简介 lvm即逻辑卷管理器(logical volume manager),它是linux环境下对磁盘分区进行管理的一种机制.lvm是建立在硬盘和分区之上的一个逻辑层,来提高分区管理的灵活性.它是 ...

  7. ACM/ICPC 之 简单DP-记忆化搜索与递推(POJ1088-滑雪)

    递推型DP 将每个滑雪点都看作起点,从最低点开始逐个由四周递推出到达此点的最长路径的长度,由该点记下. 理论上,也可以将每一点都看作终点,由最高点开始计数,有兴趣可以试试. //经典DP-由高向低海拔 ...

  8. JDK1.7 中的HashMap源码分析

    一.源码地址: 源码地址:http://docs.oracle.com/javase/7/docs/api/ 二.数据结构 JDK1.7中采用数组+链表的形式,HashMap是一个Entry<K ...

  9. Enum:Face The Right Way(POJ 3276)

    面朝大海,春暖花开 题目大意:农夫有一群牛,牛排成了一排,现在需要把这些牛都面向正确的方向,农夫买了一个机器,一次可以处理k只牛,现在问你怎么处理这些牛才可以使操作数最小? 这道题很有意思,其实这道题 ...

  10. FindinFiles - Windows文件内查找插件

    FindInFiles for Windows 今天分享一个不错的插件工具:FindInFiles.如其名,其功能和Visual Studio的Ctrl+H快捷键类似,方便Windows使用者在资源管 ...