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

用空间换时间0ms 5257kb

Posted by 12619 at 2009-08-20 16:40:27 on Problem 2081
#include<stdio.h>
#include<string.h>
#define Size 500000
int a[Size+5];
char exist[Size*10];
int main()
{
	int i,k;
	a[0]=0;
	memset(a,0,sizeof(exist));
	exist[0]=1;
	for(i=1;i<=Size;i++)
	{
		if(a[i-1]-i<=0||exist[a[i-1]-i]==1)
			a[i]=a[i-1]+i;
		else
			a[i]=a[i-1]-i;
		exist[a[i]]=1;
	}
	while(scanf("%d",&k),k!=-1)
		printf("%d\n",a[k]);
	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