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 |
我的理解,感觉不是很严密,不过AC了,大家看看是不是可以这样理解啊题目意思大概是: p+23*integer=e+28*integer=i+33*integer=x+d, 求出x。 我的思路是,既然每个等式都等于x+d,那么我每个等式来一次就可以了。然后将三个等式的结果相加即可。 p+23*interger = x+d = rp; rp初始等于28*33,然后每次rp递增28*33,直到rp%23=p,得到rp,同样道理re每次递增23*33,ri每次递增23*28,得到re,ri,最后x=(rp+re+ri-d)%21252; 完整程序如下: int p,e,i,d; int mp,me,mi; mp = 28*33; me = 23*33; mi = 23*28; scanf("%d %d %d %d",&p,&e,&i,&d); int n=1; while(p!=-1||e!=-1||i!=-1||d!=-1) { int rp,re,ri; rp = mp; re = me; ri = mi; p %= 23; e %= 28; i %= 33; while(rp%23!=p) { rp += mp; } while(re%28!=e) { re += me; } while(ri%33!=i) { ri += mi; } int x; x= (rp+re+ri-d)%21252; if(x==0) x=21252; printf("Case %d: the next triple peak occurs in %d days.\n",n,x); n++; scanf("%d %d %d %d",&p,&e,&i,&d); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator