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 |
Re:O(1)算法(中国剩余定理)In Reply To:O(1)算法(中国剩余定理) Posted by:FOR_RITZ at 2006-11-19 12:02:34 > /*用这个之前请先仔细看中国剩余定理哦*/ > #include <stdio.h> > int main() > { int p,e,i,d,a,t=0; > while(1) > { > scanf("%d%d%d%d",&p,&e,&i,&d); > if(p==-1 && e==-1 && i==-1 && d==-1) > break; > a=(5544*p+14421*e+1288*i-d+21252)%21252; > if(!a) > a=21252; > printf("Case %d: the next triple peak occurs in %d days.\n",++t,a); > } > return 0; > } 我认为代码有点小问题: 输出结果前还需判断是否a>t,如果不是,还需加上21252*k(k=1,2,3)直至a>t.因为有可能算出的peak日期(a)在指定日期(t)的前面。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator