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

9028K,0ms....

Posted by lithum at 2009-08-08 20:04:31 on Problem 2081
//poj果然是在输入数据之后才计算时间的啊。
#include<iostream>
using namespace std;

const int MaxSize=500010;
const int INFINITY=7000010;

int a[MaxSize];
bool flag[INFINITY];

int main()
{
	memset(flag,false,sizeof(flag));
	a[0]=0;
	int i;
	for(i=1;i<MaxSize;i++){
		if(a[i-1]-i>0 && !flag[a[i-1]-i]){
			a[i]=a[i-1]-i;
			flag[a[i-1]-i]=true;
		}
		else{
			a[i]=a[i-1]+i;
			flag[a[i-1]+i]=true;
		}
	}
	int k;
	while(cin>>k && k>=0) 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