poj2081

简单题

View Code
   
     
#include < iostream >
#include
< cstdio >
#include
< cstdlib >
#include
< cstring >
using namespace std;

#define maxn 500004

int f[maxn];
bool vis[maxn * 10 ];

int main()
{
// freopen("t.txt", "r", stdin);
memset(vis, 0 , sizeof (vis));
f[
0 ] = 0 ;
for ( int i = 1 ; i < maxn; i ++ )
{
f[i]
= f[i - 1 ] - i > 0 && ! vis[f[i - 1 ] - i] ? f[i - 1 ] - i : f[i - 1 ] + i;
vis[f[i]]
= true ;
}
int n;
while (scanf( " %d " , & n), n != - 1 )
printf(
" %d\n " , f[n]);
return 0 ;
}

你可能感兴趣的:(poj)