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

算法有点弱,但好歹16ms过了就是了

Posted by springfield at 2009-04-24 23:14:26 on Problem 2081
#include <iostream>
using namespace std;
int main()
{
	int a[500001],flag=0;
	char b[4000000];
	int j,w;
	for(j=0;j<4000000;j++)
	{
		b[j]=0;
	}
	a[0]=0;
	int i;
	for(i=1;i<500001;i++)
	{	
		w=a[i-1]-i;
		if(a[i-1]-i>0&&b[w]==0)
		{
			a[i]=a[i-1]-i;
			b[w]=1;
		}
		else
		{
			a[i]=a[i-1]+i;
			w=a[i];
			b[w]=1;
		}
	}
	int u;
	cin>>u;
	while(u!=-1)
	{
		cout<<a[u]<<endl;
		cin>>u;
	}
	return 0;
}
		

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