POJ-1006: biorhythms 详解1: 中国剩余定理

> 分析

>> 三个周期是三个互质数, 可以很简单的使用中国剩余定理

> 附代码

 1 /* -------------------------
 2  * 中国剩余定理
 3  * -------------------------*/
 4 #include "stdio.h"
 5
 6 int main(void)
 7 {
 8     int p = 0, e = 0, i = 0, d = 0 ;
 9     int days = 0 ;
10     int count = 0 ;
11
12     while(1)
13     {
14         scanf("%d %d %d %d", &p, &e, &i, &d) ;
15         if(-1 == d)
16             break ;
17
18         /* 5544  为28和33的公倍数, 且5544 % 23 = 1 */
19         /* 14421 为23和33的公倍数,且14421 % 28 = 1 */
20         /* 1288  为23和28的公倍数,且1288 % 33 = 1 */
21         /* 21252 = 23 * 28 * 33 */
22         days = (5544 * p + 14421 * e + 1288 * i) % 21252 ;
23         if(days <= d)
24             days += 21252 ;
25
26         printf("Case %d: the next triple peak occurs in %d days.\r\n",
27             ++count, days - d) ;
28     }
29
30     return 0 ;
31 }
时间: 2024-11-05 22:56:51

POJ-1006: biorhythms 详解1: 中国剩余定理的相关文章

POJ 1006:Biorhythms 中国剩余定理

Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 121194   Accepted: 38157 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,

转载----POJ 1006 中国剩余定理

本文为转载,源地址:   http://blog.csdn.net/dongfengkuayue/article/details/6461298 POJ 1006   Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 78980   Accepted: 23740 Description Some people believe that there are three cycles in a perso

POJ 1006 中国剩余定理

[题意]: 给定p,e,i,d,求解 (x + d) % 23 = p (x + d) % 28 = e(x + d) % 33 = i x最小正整数值 [知识点]: 中国剩余定理 [题解]: 典型的 xmodmi = ai模型,其中mi间两两互素.但该题式子较少,也可以直接自己化简带入值. [代码]: 1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <ctime> 5 #inc

poj 1006:Biorhythms(水题,经典题,中国剩余定理)

Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 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,

PKU POJ 1006 Biorhythms (中国剩余定理)

中国剩余定理 x = ai (mod mi)  ai和mi是一组数,mi两两互质,求x 令Mi = m1*m2*~mk     其中,mi不包含在内. 因为mi两两互质,所以存在x和y, st   Mi*xi + mi*yi = 1 令ei = Mi*xi ,则有: 则e0a0 + e1a1 + e2a2+ - +en-1*an-1是方程一个解 因为n%3=2,n%5=3,n%7=2且3,5,7互质       使5×7被3除余1,用35×2=70:        使3×7被5除余1,用21×1

POJ 1006 Biorhythms (数论-中国剩余定理)

Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 111285   Accepted: 34638 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,

poj 1006 Biorhythms (中国剩余定理学习)

Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 113517   Accepted: 35597 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,

数论E - Biorhythms(中国剩余定理,一水)

E - Biorhythms Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status 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

POJ - 1006 Biorhythms (中国剩余定理)

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, respec