Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 143601 | Accepted: 46190 |
Description
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
Output
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.
Source
翻译
生物周期
有的人相信每个人一出生就有着三个个循环伴随着他的一生。这三个循环分别是体能周期,情感周期和智力周期,这三个周期的时长又分别是23,28和33天。在每一个周期里会出现相应的巅峰。在巅峰期内,一个人在相应的领域(体能、情感或智力)内表现会达到最佳。例如,当达到了智力曲线的峰值,思维会变得更加敏锐并且注意力更为集中。
由于三种循环的周期长度不同,三个峰值通常也发生在不同的时期。现在我们想要确定一个人何时会出现三重巅峰(三种循环的巅峰发生于同一天)。你会得到每一个循环在今年的三重巅峰出现的日期(不一定是第一个三重巅峰)。你还会得到一个表示今年开始的日期。你的任务是确定从开始日期到下一个三重巅峰的天数。所给出的开始天数并不被计算在内。例如,如果给出的日期是10并且下一个三重巅峰发生的日期12。答案就是2,而不是3。如果有一个三重巅峰在所给出的日期发生,那么你需要给出距离下一个三重巅峰发生的天数。
输入
你会得到数种情况。对于每一种情况包括四个整数p、e、i和d。p、e、i的值分别代表三种循环在今年出现的一个巅峰时期。d的值代表所给出的开始日期并且可能小于p、e、i其中任意一个。输入的末尾将是p = e = i = d = -1。
输出
对于每一个试验情况,请在屏幕上以如下形式输出是第几种情况,并指出距离下一个三重巅峰的天数。
情况1:下一个三重巅峰将出现在1234天后。
即使答案是1也请使用day的复数形式“days”
样例输入
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
样例输出
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.
解题思路
从所给天数开始一天一天找下一个三重巅峰出现的日期,并不算什么聪明的方法吧。
注意点
要注意一下边界条件吧,得从所给日期的下一天开始找。
对比
大佬们都用的中国剩余定理来计算,只有O(1)的时间复杂度,不过感觉有点难理解,还是我太菜了。。
/*
Memory:184K
Time:735MS
*/
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int p=0,e=0,i=0,d=0,kase=1;
while(scanf("%d %d %d %d",&p,&e,&i,&d)==4&&p!=-1)
{
for(int n=d+1;;n++)
{
if((abs(p-n)%23==0)&&(abs(e-n)%28==0)&&(abs(i-n)%33==0))
{
printf("Case %d: the next triple peak occurs in %d days.\n",kase++,n-d);
break;
}
}
}
return 0;
}