| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
16MS过了,贴代码,看算法看了我好几天,中国剩余定理,很容易过,16MS过了,贴代码,看算法看了我好几天,中国剩余定理,很容易过,我不知道别人14k 0MS是怎么办到的!
#include"stdio.h"
#include"math.h"
int main(void)
{
int yu1,yu2,yu3,d;
int base1=0,base2=0,base3=0,result=0,gongbei=0;
int m;
int i,j,k;
i=1;
while(m=scanf("%d %d %d %d",&yu1,&yu2,&yu3,&d))
{
if(yu1==-1&&yu2==-1&&yu3==-1&&d==-1) break;
else if(yu1==0&&yu2==0&&yu3==0) { printf("Case %d: the next triple peak occurs in %d days.\n",i,21252-d);i++;}
else
{
gongbei=23*28*33;
for(j=1;;j++) if(28*33*j%23==1) {base1=28*33*j;break;}
for(j=1;;j++) if(23*33*j%28==1) {base2=23*33*j;break;}
for(j=1;;j++) if(23*28*j%33==1) {base3=23*28*j;break;}
result=base1*yu1+base2*yu2+base3*yu3;
for(k=1;result-d>0;k++)
result-=21252;
result+=21252;
printf("Case %d: the next triple peak occurs in %d days.\n",i,result-d);
i++;
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator