标签:
> 分析
1 /* ------------------------------ 2 * 叠加取余 3 * ----------------------------*/ 4 #include "stdio.h" 5 6 #define CYCLE_P 23 7 #define CYCLE_E 28 8 #define CYCLE_I 33 9 10 int main(void) 11 { 12 int p = 0, e = 0, i = 0, d = 0 ; 13 int count = 0 ; 14 int days = 0 ; 15 16 while(1) 17 { 18 scanf("%d %d %d %d", &p, &e, &i, &d) ; 19 if(-1 == d) 20 break ; 21 22 p = p % CYCLE_P ; 23 e = e % CYCLE_E ; 24 i = i % CYCLE_I ; 25 26 days = d + 1; 27 28 if(days <= p) 29 days = p ; 30 else 31 days += CYCLE_P - (days - p) % CYCLE_P ; 32 33 while(days % CYCLE_E != e) 34 days += CYCLE_P ; 35 36 while(days % CYCLE_I != i) 37 days += CYCLE_P * CYCLE_E ; 38 39 printf("Case %d: the next triple peak occurs in %d days.\r\n", 40 ++count, days - d) ; 41 } 42 43 return 0 ; 44 }
POJ-1006: biorhythms 详解2: 叠加取余
标签:
原文地址:http://www.cnblogs.com/codesworld/p/4714698.html