POJ 1006

POJ 1006

原题
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.
翻译
描述

有人认为,一个人的生命从出生的那一天开始就有三个周期。这三个周期是身体,情感和智力周期,分别为23天,28天和33天。每个周期的每个周期都有一个峰值。在一个周期的高峰期,一个人在相应的领域(身体,情感或精神)上表现最佳。例如,如果这是心理曲线,则思维过程将更加清晰,专心将更容易。
由于三个周期的周期不同,因此三个周期的峰值通常出现在不同的时间。我们想确定任何人何时发生三重峰(所有三个周期的峰均在同一天出现)。对于每个周期,您将获得从当年年初开始出现一个高峰(不一定是第一个高峰)的天数。您还将获得一个日期,表示为从当年年初开始的天数。您的任务是确定从给定日期到下一个三重高峰的天数。给定的日期不计算在内。例如,如果给定的日期是10,而下一个三重峰出现在第12天,则答案是2,而不是3。如果给定的日期出现三重峰,则应将下一次出现的天数指定为天数三重峰。
输入项

您会收到许多案例。每种情况的输入均由一行包含四个整数p,e,i和d的行组成。值p,e和i分别是从当年年初开始的身体,情绪和智力周期达到顶峰的天数。值d是给定的日期,可以小于p,e或i中的任何一个。所有值均为非负值,最多365,并且您可以假定在给定日期的21252天内将出现三重峰值。输入的结尾由一行表示,其中p = e = i = d = -1。
输出量

对于每个测试用例,以以下格式打印案例编号,然后显示一条消息,指示下一个三重高峰的天数:

案例1:下一个三重高峰发生在1234天。

即使答案为1,也应使用复数形式``天’’。
样本输入

0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203301203 40
-1 -1 -1 -1
样本输出

情况1:下一个三重高峰发生在21252天。
情况2:下一个三重高峰发生在21152天。
情况3:下一个三重高峰发生在19575天。
情况4:下一个三重高峰发生在16994天。
情况5:下一个三重高峰发生在8910天内。
情况6:下一个三重高峰发生在10789天。

解题思路:以后补充。需要用到中国剩余定理
下面是AC代码

#include <stdio.h>
#define BODY 23
#define EMOT 28
#define INTI 33
int main()
{
	int k=1,temp, t1, t2, t3, t4, t5;
	int n=1;
	int p,e,i,d;
	int x=1;
	scanf("%d %d %d %d",&p,&e,&i,&d);
	while(p!=-1 && e!=-1 && i!=-1 && d!=-1)
	{
		for(k=1;k<100;++k)
		{
			temp=28*33;
			if((temp*k) % 23 == 1)
			{
				t1=temp*k;
				break;
			}
		}
		for(k=1;k<100;++k)
		{
			temp=23*33;
			if((temp*k) % 28 == 1)
			{
				t2=temp*k;
				break;
			}
		}
		for(k=1;k<100;++k)
		{
			temp=23*28;
			if((temp*k) % 33 == 1)
			{
				t3=temp*k;
				break;
			}
		}
		
		t4 = (t1*p + t2*e + t3*i - d)%(23*28*33);
		if(t4<=0)
			t4+=21252;
		printf("Case %d: the next triple peak occurs in %d days.\n", n, t4 );
		n++;
		scanf("%d %d %d %d",&p,&e,&i,&d);
	} 
	return 0;
}
发布了22 篇原创文章 · 获赞 39 · 访问量 4044

猜你喜欢

转载自blog.csdn.net/weixin_44895666/article/details/102341267