Biorhythms
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 138926   Accepted: 44590

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. 好吧!题名就把我唬住了,没见过的单词啊。 没事,google一下。

  哈! 还是不懂啥意思。 算了,直接看题目。

  题目说 : 有些人认为啊,从人一出生开始,有三个周期就开始运转了,啥周期呢?身体、情感和智力周期。 它们的周期时长分别是23天,28天,33天。 然后呢,它们都会有一个顶峰嘛,在这个顶峰的时候,我们相对应的表现就会很牛逼。比如,如果是心理曲线,思考会更快,而且更容易集中。
又因为呢,这三个周期的顶峰不一样,通常都会在不同的时间出现。 然后呢,我们现在想算一下,哪一天是三个顶峰同时出现(三buff齐加,上天了)。现在给出三个日期,分别对应于体力,情感,智力离今年第一天出现峰值的日期。然后再给出一个起始日期,要求从这一天开始,算出最少再过多少天后三个峰值同时出现。 解题: 我们假设这三个周期都是正弦波,画个图出来看看。
 
 

图画得非常丑啊! 但是没关系,我们来看,要三buff齐开,就是要刚好三个顶峰凑在一起了。 假设我们已经知道了,三个顶峰将会在S天后出现,那么,S = N1 + T1*K1 = N2 + T2*K2=  N3 + T3*K3。 N是指单一顶峰出现的时间,T代表周期,K是正整数。

那我们现在有一种简单的做法,穷举! 先试试。

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T1 = 23;
int T2 = 28;
int T3 = 33;
int count = 0;
while(scanner.hasNext()){
count++;
int N1 = scanner.nextInt();
int N2 = scanner.nextInt();
int N3 = scanner.nextInt();
int C = scanner.nextInt();
if(N1 ==-1 && N2 ==-1 && N3 == -1 && C==-1){
return;
}
for(int i = 1 ; i <= 21252+C ;i++){
if((i-N1)%T1==0){

}else{
continue;
}

if((i-N2)%T2==0){

}else{
continue;
}
if((i-N3)%T3==0){

}else{
continue;
}
if(i-C<=0){
continue;
}

System.out.println("Case "+count+": the next triple peak occurs in "+(i-C)+" days.");
break;
}
}
}
}

  OK! 穷举的代码得出正确结果。 可是。。。。   超时了。 好~  不用这么拙劣的办法。我们先来看看,中国剩余定理

  看完之后我们再来解题, S = N1 + T1*K1 = N2 + T2*K2=  N3 + T3*K3

  我们可以拆解成 :

S%T1 = N1 ,

  S%T2 = N2 ,

  S%T3 = N3.

  这样就可以用中国剩余定理了。

  


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(水题,经典题,中国剩余定理)

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

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

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

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

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

  7. POJ - 1006 Biorhythms 周期相遇 两个思路程序

    Description Some people believe that there are three cycles in a person's life that start the day he ...

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

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

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

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

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

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

随机推荐

  1. 40.Unique Binary Search Trees(不同的二叉搜索树)

    Level:   Medium 题目描述: Given n, how many structurally unique BST's (binary search trees) that store v ...

  2. 页面跳转到Area区域连接

    @Html.ActionLink("主页", "Index", new { controller = "Test", Action = &q ...

  3. JS事件循环(Event Loop)机制

    前言 众所周知,为了与浏览器进行交互,Javascript是一门非阻塞单线程脚本语言. 为何单线程? 因为如果在DOM操作中,有两个线程一个添加节点,一个删除节点,浏览器并不知道以哪个为准,所以只能选 ...

  4. mongodb使用本地日期查询

    db.getCollection('userLog').find({createAt:{"$gt":new Date("2018-08-05"),"$ ...

  5. C# string.Format json格式字符串报错”输入字符串的格式不正确“

    当我们在string.Format中传入Json字符串时,会报”输入字符串的格式不正确“,这是因为json的"{"符号的问题,最开始我是想着用转义一下"{",但 ...

  6. 大数据基础环境--jdk1.8环境安装部署

    1.环境说明 1.1.机器配置说明 本次集群环境为三台linux系统机器,具体信息如下: 主机名称 IP地址 操作系统 hadoop1 10.0.0.20 CentOS Linux release 7 ...

  7. 项目使用gulp的配置编译sass笔记

    Node环境 通过 node.js 网站下载了安装包进行安装 node.js, npm也会一起安装 node --version # 查看node.js版本 npm --version #查看npm版 ...

  8. MongoDB服务的安装与删除

    服务的安装: 在MongoDB的目录下创建两个文件夹 data和logs, 在通过cmd进入bin目录下,执行命令: mongod --dbpath "C:\Program Files\Mo ...

  9. 云数据库POLARDB产品解读之二:如何做到高性价比

    现在做任何事情都要看投入产出比,对应到数据库上其实就是性价比.POLARDB作为一款阿里自研数据库,经常被问的问题是:性能怎么样?能不能支撑我的业务?价格贵不贵?很显然,在早期调研阶段,对稳定性.可靠 ...

  10. ubuntu下安装apidoc

    1.到http://nodejs.cn/download/下载nodejs 可以复制链接 使用wget下载更加快速 选择对应的操作系统位数 下载到/usr/local/src 此处强烈不建议编译安装 ...