| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
0ms#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator