标签:des style blog http color 使用
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 111426 | Accepted: 34702 |
Description
Input
Output
Sample Input
0 0 0 0 0 0 0 100 5 20 34 325 4 5 6 7 283 102 23 320 203 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.
一开始自己做这道题时,样例全可以过,可就是AC不了。
从http://www.cnblogs.com/walker01/archive/2010/01/23/1654880.html处摘抄的剩余定理的有关资料,他讲的很明白,很详细。
在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。具体解法分三步:
根据剩余定理:
1.(23*28*i)%33=1; i=2; 23*28*2=1288;
2.(23*33*j)%28=1; j=19; 23*33*19=14421;
3.(28*33*k)%23=1; k=6; 28*33*6=5544;
由此就可以得出:5544*p+14421*e+1288*i ;再根据题意做适当的调整。
#include <stdio.h> int main() { int p, e, i, d; int num = 0; int days; while(scanf("%d%d%d%d", &p, &e, &i, &d) != EOF) { if(p==-1 &&e==-1 &&i==-1 &&d==-1) break ; days=(5544*p+14421*e+1288*i-d+21252)%21252; //后面加21252是防止它变成负数 if(days ==0) days=21252; printf("Case %d: the next triple peak occurs in %d days.\n", ++num,days); } return 0; }
标签:des style blog http color 使用
原文地址:http://www.cnblogs.com/fengxmx/p/3812558.html