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. linux缺頁異常處理--內核空間[v3.10]

    缺頁異常被觸發通常有兩種情況—— 1.程序設計的不當導致訪問了非法的地址 2.訪問的地址是合法的,但是該地址還未分配物理頁框 下面解釋一下第二種情況,這是虛擬內存管理的一個特性.盡管每個進程獨立擁有3 ...

  2. 一些常ArcGIS常用简单算法 C#

    最近开始重构不顺眼的辣鸡代码,顺带将某个模块的一个算法辅助类贴到这里. /// <summary> /// 算法逻辑辅助类 /// </summary> internal st ...

  3. C# 编程--数组

    数组 可以帮我我们一次声明存储多个相同类型的变量.用来解决同一类大量数据在内存存储和运算的功能特点:连续.同一类数据数组定义==>赋值==>取值    定义:        int[] n ...

  4. mybatis-generator 代码自动生成插件

    Hibernate 可以选择MyEclipse Datebase Explorer 或者是 Hibernate-tools 等工具来自动生成映射文件和实体类. mybatis 当然也要有!下面简单介绍 ...

  5. 【leetcode】989. Add to Array-Form of Integer

    题目如下: For a non-negative integer X, the array-form of X is an array of its digits in left to right o ...

  6. 阿里云入选Gartner 2019 WAF魔力象限,唯一亚太厂商!

    近期,在全球权威咨询机构Gartner发布的2019 Web应用防火墙魔力象限中,阿里云Web应用防火墙成功入围,是亚太地区唯一一家进入该魔力象限的厂商! Web应用防火墙,简称WAF.在保护Web应 ...

  7. python--内置函数、匿名函数、递归调用

    匿名函数 有名函数: def func1(x): print(func1) 结果: <function func1 at 0x00000000005C3E18> 匿名函数: func2=l ...

  8. PIC16F877A的TIME0学习

    计算溢出时间根据晶振频率4Mhz,TMR0=6,PSA2~PSA0 = 1:4. 因为好像外部晶振在给PIC的时候多分了一次1:4.所以PSA2~PSA0取1:4刚好 数完250次的时间=(1/4Mh ...

  9. jdbc——java连接sql server 过程

    首先要去下一个关于sql的驱动jar包,叫做sqljdbc4.jar 然后更新项目的build path,加入这个jar包 前几步有问题的看该博客 https://blog.csdn.net/qq24 ...

  10. 【Linux】【Fabric】在ubuntu容器中安装Fabric环境

    前言 想在docker容器中安装docker部署fabric网络,有了以下尝试. 尝试了centos镜像.redhat镜像都没解决docker容器中安装运行docker的问题,最后ubuntu成功了! ...