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. 查看x86主機是否支援64bit in Linux

    $cat /proc/cpuinfo 查看flags 欄位中是否有 lm (long mode)

  2. Cas 使用maven的overlay搭建开发环境 (二)

    关于cas-server的安装.部署网上教程很多.但是使用Cas,只通过部署时修改配置是无法满足产品需求的,因此需要我们改造Cas.本文讲解如何使用maven的overlay无侵入的改造Cas. 什么 ...

  3. 在Linux上搭建私有git仓库

    最近在学Linux,顺便将自己的服务器用起来,不然又得废弃一年.这次是跟着网上的教程做一个简单的git私有仓库,复杂完整的git系统还需使用gitlib系统. 首先在linux上安装git yum i ...

  4. C#链式编程

    一.基本链式格式 class Program { static void Main(string[] args) { Console.WriteLine("Hello World!" ...

  5. Codeforces 364D 随机算法

    题意:给你一个序列,定义ghd为一个序列中任意n / 2个数的gcd中最大的那个,现在问这个序列的ghd为多少. 思路:居然是论文题...来自2014年国家集训队论文<随机化算法在信息学竞赛中的 ...

  6. 42th-2

    '''   1, 元祖(2,3)'''def summ2(self, *args):    '''这是一个求一系列数平方和的函数'''    s = 0    for i in args:  #历遍元 ...

  7. JindoFS解析 - 云上大数据高性能数据湖存储方案

    JindoFS背景 计算存储分离是云计算的一种发展趋势,传统的计算存储相互融合的的架构存在一定的问题, 比如在集群扩容的时候存在计算能力和存储能力相互不匹配的问题,用户在某些情况下只需要扩容计算能力或 ...

  8. java html生成图片html2canvas,Canvas2Image

    <html> <div id="pic" style="margin-left: 500px;position:fixed;opacity:0;&quo ...

  9. apue 第10章 信号signal

    每种信号都有名字,都是以SIG开头 信号机制最简单的接口是signal函数 #include <signal.h> typedef void (*sighandler_t)(int); s ...

  10. 低价购买 (动态规划,变种最长下降子序列(LIS))

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...