HDU 1370 Biorhythms
来源:互联网 发布:starry night观星软件 编辑:程序博客网 时间:2024/06/06 10:46
Biorhythms
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 669 Accepted Submission(s): 266
Problem 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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
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
10 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; Pacific Northwest 1999
Recommend
Eddy
今日做第一条非水题就系~~~中国剩女定理!
首先就系睇张教授既PDF,然后按照算法框架写出扩展欧几里德,模线性方程, 中国剩女定理函数,直接套然后减去d就ok,注意第一个Case由第一个输入既数决定。
下面直接贴代码:
43191642011-08-03 10:23:16Accepted13700MS204K1248 BC++10SGetEternal{(。)(。)}!
#include <iostream>#include <vector>using namespace std;vector<int>A, N;int EX_GCD(int a, int b, int &x, int &y){ int d, tx, ty; if (b == 0) { x = 1; y = 0; return a; } d = EX_GCD(b, a % b, tx, ty); x = ty; y = tx - (a / b) * ty; return d;}int MLE(int a, int b, int n){ int d, x, y; d = EX_GCD(a, n, x, y); if (b % d == 0) { x = x * b / d % n; return x; } return 0;}int CRT(){ int x = 0, n = 1, i, bi; for (i = 0; i < N.size(); i++) n *= N[i]; for (i = 0; i < A.size(); i++) { bi = MLE(n / N[i], 1, N[i]); x = (x + A[i] * bi * (n / N[i])) % n; } return x;}int Solve(int p, int e, int i, int d){ int ans, add = 23 * 28 * 33; A.clear(); A.push_back(p % 23); A.push_back(e % 28); A.push_back(i % 33); ans = CRT(); while (ans <= d) ans += add; return ans - d;}int main(){ int C, p, e, i, d, ans; N.clear(); N.push_back(23); N.push_back(28); N.push_back(33); scanf("%d", &C); while (1) { scanf("%d%d%d%d", &p, &e, &i, &d); if (p == -1 && e == -1 && i == -1 && d == -1) break; ans = Solve(p, e, i, d); printf("Case %d: the next triple peak occurs in %d days.\n", C++, ans); } return 0;}
其实系尼条算系模版题…………
- HDU 1370 Biorhythms
- 【HDU】 1370 Biorhythms
- HDU 1370 Biorhythms
- HDU 1370 Biorhythms
- ACM 数论 hdu 1370 Biorhythms
- Biorhythms HDU
- POJ 1006 && HDU 1370 Biorhythms(水~)
- HDU 1370 Biorhythms (中国剩余定理)
- hdu 1370 Biorhythms(中国剩余定理)
- HDU 1370 Biorhythms 中国剩余定理
- 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms
- HDU 1370 Biorhythms(中国剩余定理 + 拓展欧几里得)
- HDU 1370 Biorhythms (中国剩余定理, 简单套用)
- 中国剩余定理 Biorhythms HDU
- hdoj-1370-Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- 查看Oracle执行计划的几种方法
- js实现页面跳转的几种方式
- iphone开发一些好的网站推荐
- 网络dos命令(二)
- ubuntu 11.04上oracle 11g r2的TNS-12541:TNS-12560:TNS-00511错误处理
- HDU 1370 Biorhythms
- websphere 内存溢出处理
- POJ1364/ZOJ1260 King(差分约束,spfa)
- Socket参数用法(1)
- Android实战之HttpClient
- poj1046 枚举法
- HDOJ 2084 数塔
- 设计模式之(一)工厂模式Factory
- java 读取propertites