| ||||||||||
| 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:高手指点指点呀,怎么总是runtime error?pboblem1006In Reply To:高手指点指点呀,怎么总是runtime error?pboblem1006 Posted by:qingfang at 2008-04-23 12:11:32 > #include<stdio.h>
> #include<stdlib.h>
> void main(void)
> {
> int a[100],b[100],c[100],d[100];
> int i,j,n;
> for(i=0; ;i++)
> {
> scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
> if(a[i]==-1&&b[i]==-1&&c[i]==-1&&d[i]==-1)
> {
> break;
> }
> }
> for(j=0;j<i;j++)
> {
> for(n=1;n<21253;n++)
> {
> if((n-a[i])%23==0&&(n-b[j])%28==0&&(n-c[i])%33==0)
> {
> printf("Case %d: the next triple peak occurs in %d days.\n",j+1,n-d[j]);
> break;
> }
> }
> }
> system("PAUSE");
> }
遍历是效率最低的,你可以稍微用一下数学技巧,如把步长修改为33,初始条件改一下,应该就可以提高问33倍速度了.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator