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 |
仔细看看有没有可能哪里数组越界吧,runtime error,问为什么就是程序有问题In Reply To:Re:请问为什么Runtime error? Posted by:noskill at 2005-04-26 23:39:59 这里好多题目数据都加了的 递归也可以看一下,会不会溢出 > 我在zju AC了,为什么这里Runtime error? > #include<iostream.h> > #include<memory.h> > #include<math.h> > int a[1010],tn,f,t,d; > bool v[1010],num[10001]; > int check() > { > int i,m=0,sum=a[tn+f-1]; > for(i=tn-1+f-1;i>=tn-d+1+f-1;i--) > {sum+=a[i];if(!num[sum]){m=1;break;}} > return m; > } > int antiprime() > { > int i; > if(tn>=2&&check())return 0; > if(tn==t-f+1)return 1; > for(i=f;i<=t;i++) > { > if(!v[i]){ > tn++;v[i]=1;a[tn+f-1]=i; > if(antiprime())return 1; > else{tn--;v[i]=0;} > } > } > return 0; > } > int main() > { > int i,j; > for(i=3;i<=10000;i++) > { > for(j=2;j<=(int)sqrt(i);j++) > if(i%j==0){num[i]=1;break;} > } > while(cin>>f>>t>>d,d!=0) > { > memset(v,0,sizeof(v)); > memset(a,0,sizeof(a)); > tn=0; > if(antiprime()) > { > for(i=f;i<t;i++)cout<<a[i]<<','; > cout<<a[t]<<endl; > } > else cout<<"No anti-prime sequence exists."<<endl; > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator