Biorhythms

Time Limit: 1000MS Memory Limit: 10000KB 

Problem 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.

Example 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

Example 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.
 #include <cstdio>
int main(int argc, const char * argv[]){
int physical, emotional, intellectual, date;
int physicalCycle = , emotionalCycle = , intellectualCycle = , LCM = ;
int caseIndex = ;
while (scanf("%d %d %d %d", &physical, &emotional, &intellectual, &date)) {
if (physical < || emotional < || intellectual < || date <) break;
caseIndex ++;
physical ? physical = physical % physicalCycle : NULL;
emotional ? emotional = emotional % emotionalCycle : NULL;
intellectual ? intellectual = intellectual % intellectualCycle : NULL; int i = , temp;
while () {
temp = i * intellectualCycle + intellectual;
if ((temp % physicalCycle == physical) && (temp % emotionalCycle == emotional)) break;
i++;
}
temp = temp <= date ? temp + LCM : temp;
temp -= date;
printf("Case %d: the next triple peak occurs in %d days.\n", caseIndex, temp);
}
return ;
}//0ms 108kb g++ 1047B

算法练习之:Biorhythms的更多相关文章

  1. [POJ] #1006# Biorhythms : 最小公倍数/同余问题

    一. 题目 Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127263   Accepted: 403 ...

  2. Biorhythms(中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127339   Accepted: 40342 Des ...

  3. 算法之路 level 01 problem set

    2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...

  4. B树——算法导论(25)

    B树 1. 简介 在之前我们学习了红黑树,今天再学习一种树--B树.它与红黑树有许多类似的地方,比如都是平衡搜索树,但它们在功能和结构上却有较大的差别. 从功能上看,B树是为磁盘或其他存储设备设计的, ...

  5. 分布式系列文章——Paxos算法原理与推导

    Paxos算法在分布式领域具有非常重要的地位.但是Paxos算法有两个比较明显的缺点:1.难以理解 2.工程实现更难. 网上有很多讲解Paxos算法的文章,但是质量参差不齐.看了很多关于Paxos的资 ...

  6. 【Machine Learning】KNN算法虹膜图片识别

    K-近邻算法虹膜图片识别实战 作者:白宁超 2017年1月3日18:26:33 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...

  7. 红黑树——算法导论(15)

    1. 什么是红黑树 (1) 简介     上一篇我们介绍了基本动态集合操作时间复杂度均为O(h)的二叉搜索树.但遗憾的是,只有当二叉搜索树高度较低时,这些集合操作才会较快:即当树的高度较高(甚至一种极 ...

  8. 散列表(hash table)——算法导论(13)

    1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...

  9. 虚拟dom与diff算法 分析

    好文集合: 深入浅出React(四):虚拟DOM Diff算法解析 全面理解虚拟DOM,实现虚拟DOM

随机推荐

  1. 安装完Kali linux 之后 需要配置的一些 常用软件 记录

    apt 阿里云开源镜像站 deb http://mirrors.aliyun.com/kali sana main non-free contribdeb http://mirrors.aliyun. ...

  2. Spring MVC的异常统一处理方法

    我们经常需要统一配置项目的异常处理,又希望统一处理异常代码,同时不侵入原有的正常代码.我们可以通过以下三种方式实现统一处理项目的自定义异常. 通过SimpleMappingExceptionResol ...

  3. 微信公众号支付(一):获取用户openId

    一.获取apikey,appsecret与商户号 注册公众号.商户号 二.获取用户的OpenId 1.设置[授权回调页面域名] 官方解释:用户在网页授权页同意授权给公众号后,微信会将授权数据传给一个回 ...

  4. JVM笔记4:Java内存分配策略

    简单来说,对象内存分配主要是在堆中分配.但是分配的规则并不是固定的,取决于使用的收集器组合以及JVM内存相关参数的设定 以下介绍几条基本规则(使用的ParNew+Serial Old收集器组合): 一 ...

  5. Scala闭包

    假如我们定义如下的函数: (x:Int) => x + more 这里我们引入一个自由变量more.它不是所定义函数的参数,而这个变量定义在函数外面,比如: var more =1 那么我们有如 ...

  6. JQ判断按钮,复选框是否选中

    var oRdoValue=$("#Radio1").is (":checked")?"男":"女"; //获取单选框按 ...

  7. CAS 单点登录,通过ticket 获取登录用户

    string url =SSOValidate+"?service=" + WebValidate + "&ticket=" + Ticket + &q ...

  8. Eclipse搭建服务器

    一.首先,依次点击Window -->preferences-->Server-->Runtime environment -->add,再选择Apache,选择TOMcat的 ...

  9. Js~数组的操作push,pop,shift,unshift

    说几个概念: 队列:先进先出堆栈:先进后出 shift:从集合中把第一个元素删除,返回这个元素的值pop:从集合中把最后一个元素删除,返回这个元素的值 unshift:在集合开头添加一个或者多个元素, ...

  10. 2013年10月13日学习:SQL通过命令语句来创建表

    优点:操作简单,不容易出错,易于调试 缺点:需要记住命令.命令多了就容易混淆,是吧!但是熟悉了时间长了就OK了! step 1. 新建数据库,命名为Test 点击图形化界面中的新建查询,此时就可以输入 ...