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 penghaitao at 2013-09-29 16:17:59 on Problem 2081
#include<iostream>
using namespace std;

int a[5000010]={0};
int b[5000010]={0};

int main()
{
	a[0]=0;
	b[0]=-1;
	int i,x;
	for(i=1;i<500010;i++)
	{
		a[i]=a[i-1]-i;
		if(a[i]<0||b[a[i]]==-1)
				a[i]=a[i-1]+i;
		b[a[i]]=-1;
	}
	while(cin>>x)
	{
		if(x==-1)break;
		cout<<a[x]<<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