Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

同志们帮帮忙,怎么老超时,而且运行不了?

Posted by 00411082 at 2005-03-29 16:58:55 on Problem 2081
同志们帮帮忙,怎么老超时,而且运行不了?
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator