直接枚举(16MS,可以接受),测试数据有点纠结。
1 # include <stdio.h>
2
3 int p, e, i, d;
4 const int add[] = {1, 23, 28, 23*28, 33, 23*33, 28*33};
5
6 int mod(int x, int m);
7
8 int main()
9 {
10 int cnt, day, sta;
11
12 cnt = 0;
13 while (1)
14 {
15 scanf("%d%d%d%d", &p, &e, &i, &d);
16 if (p==-1 && e==-1 && i==-1 && d==-1) break;
17 ++cnt;
18 for (day = d+1; day <= 21252+d; )
19 {
20 sta = mod(day-p, 23) + mod(day-e, 28)*2 + mod(day-i, 33)*4;
21 if (sta == 7) break;
22 day += add[sta];
23 }
24 day -= d;
25 printf("Case %d: the next triple peak occurs in %d days.\n", cnt, day);
26 }
27
28 return 0;
29 }
30
31 int mod(int x, int m)
32 {
33 if (x % m) return 0;
34 return 1;
35 }