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

Posted by bryant03 at 2014-08-01 01:03:00 on Problem 2081
#include <stdio.h>
#include <cstring>
int a[500001],num;
bool b[3100000];
int main()
{
	a[0]=0;
	memset(b,true,sizeof(b));
	for(int i=1;i<=500000;i++)
	{
		if(a[i-1]-i>0)
		{
			if(b[a[i-1]-i])
			{
				a[i]=a[i-1]-i;
				b[a[i]]=false;
			}
			else
            {
                a[i]=a[i-1]+i;
                b[a[i]]=false;
            }
		}
		else
		{
			a[i]=a[i-1]+i;
			b[a[i]]=false;
		}
	}
	while(scanf("%d",&num))
	{
		if(num==-1)
			break;
		printf("%d\n",a[num]);
	}
	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