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 zhanggt1994 at 2013-04-05 23:00:52 on Problem 2081
#include<iostream>
using namespace std;

int a[500006],visit[8000000];
int main()
{
	a[0]=0;
	memset(visit,0,sizeof(visit));
	visit[0]=1;
	for(int i=1;i<=500000;i++)
	{
		if(a[i-1]-i<0)
			a[i]=a[i-1]+i;
		else
		{
			if(visit[a[i-1]-i])
				a[i]=a[i-1]+i;
			else
				a[i]=a[i-1]-i;
		}
		visit[a[i]]=1;
	}
	int k;
	while(cin>>k&&k!=-1)
	{
		cout<<a[k]<<endl;
	}
	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