| ||||||||||
| 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 | |||||||||
是不是你数组a,sum开的太小了,加上一个数组就多出了一片预留空间,内存连续使用,让你有足够内存使用In Reply To:POJ 我对你太不了解了 !!!!!!!!! Posted by:AlbertLiu at 2008-09-10 00:06:28 > 下面是我的代码,其中第六行是个根本没用的数组,但不加它就WA 加了就AC 害得我找错找了半天,当我把从2到10000的所有数全比较一遍后都没发现错误!!!!!
>
> Run ID 4048280 AC
> Run ID 4048288 WA
>
> #include <stdio.h>
> #include <iostream>
> using namespace std;
> #define N 700
> int a[N],sum[N];
> //int x[10000]; // 就是这个数组,根本就没用,但加上就AC 不加就WA
> int main()
> {
> int i,j,k,n,count;
> a[0]=2,a[1]=3;
> sum[0]=0,sum[1]=2,sum[2]=5;
> i=k=2;
> while(i<N)
> {
> ++k;
> for(j=0;j<i;++j)
> if(k%a[j]==0)
> break;
> if(j==i)
> {
> a[i]=k;
> sum[i+1]=sum[i]+k;
> ++i;
> }
> }
> while(scanf("%d",&n)&&n)
> {
> i=count=0;
> while( n>a[i] && n%a[i] && i<50 ) ++i;
> if(a[i]>=n || i==50)
> ++count;
> k=0;
> while(sum[k]<n) ++k;
> k+=2;
> while(k>2)
> {
> --k;
> i=0;
> while(sum[k+i]-sum[i]<n) ++i;
> if( sum[k+i]-sum[i]==n )
> count++;
> }
> cout<<count<<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