http://poj.org/problem?id=1006

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 138219   Accepted: 44274

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. CRT+细节处理
 #include <algorithm>
#include <cstdio> using namespace std; int a[],str,m[],p[],cnt,tot,ans; void exgcd(int a,int b,int &x,int &y)
{
if(!b) { x=; y=; return ; }
exgcd(b,a%b,x,y);
int tmp=x; x=y;
y=tmp-a/b*y;
}
int CRT()
{
int ret=;
for(int i=;i<=;i++)
{
int t=tot/p[i],x,y;
exgcd(t,p[i],x,y);
ret=(ret+t*x*a[i])%tot;
}
return ret>=?ret:(ret+tot);
} int main()
{
p[]=; p[]=; p[]=;
tot=p[]*p[]*p[];
for(;scanf("%d%d%d%d",&a[],&a[],&a[],&str);)
{
if(a[]==-&&a[]==-&&a[]==-&&str==-) break;
ans=CRT()-str; cnt++;
for(;ans<=;) ans+=tot;
printf("Case %d: the next triple peak occurs in %d days.\n",cnt,ans);
}
return ;
}

POJ——T 1006 Biorhythms的更多相关文章

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

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

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

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

  3. Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期

    1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...

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

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

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

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

  6. [POJ 1006] Biorhythms C++解题

        Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 107569   Accepted: 33365 ...

  7. poj 1006:Biorhythms(水题,经典题,中国剩余定理)

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

  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: 127263   Accepted: 403 ...

随机推荐

  1. 实习第一天(安装svn管理工具跟tomcat插件)

    在eclipse中安装svn管理解压工具是有好几种方法. 方法1 1>可以直接下载svn插件subclipse,之后进行解压 2>然后将将插件包features和plugins目录中的文件 ...

  2. Django 框架篇(四) : 视图(view)详解 以及 路由系统(url)

    |--Django的View(视图) |-- CBV和FBV: |-- 给视图增加装饰器: |-- request对象: |-- response对象: |-- Django的路由系统(url): | ...

  3. POJ 3622 multiset

    思路: 放一个链接 是我太懒了 http://blog.csdn.net/mars_ch/article/details/52835978 嗯她教的我(姑且算是吧) (一通乱搞就出来了-) //By ...

  4. BZOJ 1050 枚举+并查集

    思路: 枚举最大边 像Kruskal一样加边 每回更新一下 就搞定了- //By SiriusRen #include <cstdio> #include <cstring> ...

  5. 超级硬件代理解决企业Web提速上网问题

    超级硬件代理解决企业Web提速上网问题 需求分析: XX集团是五家企业重组建立的特大型工程勘察设计咨询企业,下设10多个分公司,上网人数众多.有多台WEB server,对外服务,访问量及大.以前无论 ...

  6. Dom4j 查找节点或属性

    Dom4j  查找节点或属性 例如 1 查找下面xml中的student节点的age属性, xpathstr="/students/student/@age"; 2 查找下面xml ...

  7. 威联通212P 在admin用户密码正确情况下仍然无法登录WEB页面解决办法

    *登录 telnet 执行以下语句: [~] # cp /etc/default_config/passwd /mnt/HDA_ROOT/.config/passwd[~] # cp /etc/def ...

  8. 2018 NOIP备战计划

    2018 NOIP目标 (1)刷完紫书数论习题 (2)听51nod讲座和习题,根据其知识结构来备战. (3)刷完紫书动规 (4)初赛前两个星期左右开始复习 刷紫书动规的时候感觉偏难,进步缓慢.应该自己 ...

  9. 【hiho39】二分·归并排序之逆序对

    近期申请了微软的暑假实习,4号就要在线笔试了,在线測试系统用的是http://hihocoder.com/,今天试手做了一道题. [题目] 原题链接:http://hihocoder.com/cont ...

  10. Swift编程语言初探

    继WWDC2014后,新的编程语言Swift浮出水面.它具有高速.现代.安全.可交互等特征,而且其语法简单,入门门槛低,有望替代语法复杂难懂的Objective-C语言.据其作者Chris Lattn ...