| ||||||||||
| 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 | |||||||||
同志们帮帮忙,怎么老超时,而且运行不了?同志们帮帮忙,怎么老超时,而且运行不了?
#include<iostream.h>
void main()
{
int a[500001],k,num;
a[0]=0;
for(int i=1;i<500001;i++)
{
num=0;
if(a[i-1]<=i) a[i]=a[i-1]+i;
else {
a[i]=a[i-1]-i;
for(int k=1;k<i;k++)
{
if(a[k]==a[i]) {num=1;break;}
}
if(num==1) a[i]=a[i-1]+i;
}
}
for(;;)
{
cin>>k;
if(k==-1) break;
cout<<a[k]<<endl;
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator