POJ 1006 Biorhythms
来源:互联网 发布:java list排序算法 编辑:程序博客网 时间:2024/05/19 23:10
Biorhythms
Time Limit: 1000MS
Memory Limit: 10000KTotal Submissions: 112801
Accepted: 35263
Memory Limit: 10000KTotal Submissions: 112801
Accepted: 35263
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.
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.
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 00 0 0 1005 20 34 3254 5 6 7283 102 23 320203 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
East Central North America 1999
题目链接 :http://poj.org/problem?id=1006
题目大意 :人的体力,情感,生理周期分别为23,28和33天,现在给出三个日期:体力,情感,生理的峰值日期和一个起始日期,求出再过多少天后三个峰值在同一天出现
题目分析 :设D1,D2,D3来表示体力,情感,生理出现峰值的日期,T1,T2,T3来表示体力,情感,生理的周期,现在要求一个最小的数N,满足N % T1 = N1, N % T2 = N2, N % T3 = N3 用中国剩余定理(http://baike.baidu.com/view/157384.htm?from_id=11200132&type=syn&fromtitle=%E4%B8%AD%E5%9B%BD%E5%89%A9%E4%BD%99%E5%AE%9A%E7%90%86&fr=aladdin)因为23,28,33三个数互质令:
n1为28*33*a%23 == 1的最小整数, 这里通过打表找到a = 6
n2为23*33*b%28 == 1的最小整数, b = 19
n3为23*28*c%33 == 1的最小整数, c = 2
sum <= d时
sum = (n1 * p + n2 * e + n3 * i) % 21252
否则再加21252
题目链接 :http://poj.org/problem?id=1006
题目大意 :人的体力,情感,生理周期分别为23,28和33天,现在给出三个日期:体力,情感,生理的峰值日期和一个起始日期,求出再过多少天后三个峰值在同一天出现
题目分析 :设D1,D2,D3来表示体力,情感,生理出现峰值的日期,T1,T2,T3来表示体力,情感,生理的周期,现在要求一个最小的数N,满足N % T1 = N1, N % T2 = N2, N % T3 = N3 用中国剩余定理(http://baike.baidu.com/view/157384.htm?from_id=11200132&type=syn&fromtitle=%E4%B8%AD%E5%9B%BD%E5%89%A9%E4%BD%99%E5%AE%9A%E7%90%86&fr=aladdin)因为23,28,33三个数互质令:
n1为28*33*a%23 == 1的最小整数, 这里通过打表找到a = 6
n2为23*33*b%28 == 1的最小整数, b = 19
n3为23*28*c%33 == 1的最小整数, c = 2
sum <= d时
sum = (n1 * p + n2 * e + n3 * i) % 21252
否则再加21252
#include <cstdio>int const limit = 21252;int main(){ int p,e,i,d,sum,T = 1; int n1, n2, n3; while(scanf("%d%d%d%d",&p,&e,&i,&d) != EOF && (p+e+i+d) != -4) { n1 = 28 * 33 * 6; n2 = 23 * 33 * 19; n3 = 23 * 28 * 2; sum = (n1*p + n2*e + n3*i) % limit; if(sum - d <= 0) sum += limit; printf("Case %d: the next triple peak occurs in %d days.\n",T++,sum - d); }}//打表程序/*#include <cstdio>int main(){ int n, ans; scanf("%d",&n); for(int i = 1; i < n; i++) if(28*33*i%23 == 1) printf("%d\n",i);}*/
0 0
- poj 1006 Biorhythms
- poj 1006 Biorhythms
- poj 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- 【POJ】1006 Biorhythms
- POJ-1006:Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 Biorhythms
- POJ 1006 Biorhythms
- Poj 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 hdu1370 Biorhythms
- 【POJ】1006 Biorhythms
- poj 1006 Biorhythms
- Qt - QTimer更新ui
- C++实现开机启动
- HDU 1082
- size_type与size_t的机器无关性
- poj 3320 Jessica's Reading Problem
- POJ 1006 Biorhythms
- LeetCode: Max Points on a Line
- 树链剖分-链的剖分(线段树维护+离线操作)
- 关于ios越狱开发的那些事
- 7518爱的是看了就关联方看见过开了房7518季后赛的规范健康
- 微软MSDN订阅介绍
- cmake函数参数解析
- VC 调用 VB 的DLL
- 老罗锤子手机发布会,我感到深深地愧疚!