http://poj.org/problem?id=3537
// File Name: poj3537.cpp
// Author: bo_jwolf
// Created Time: 2013年10月04日 星期五 20:03:34
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
const int maxn = 2005;
int sg[ maxn ];
int dfs( int n ){
bool vis[ maxn ] = { 0 };
int i;
if( n <= 0 )
return 0;
if( sg[ n ] >= 0 )
return sg[ n ];
for( i = 1; i <= n; ++i )
vis[ dfs( n - i - 2 ) ^ dfs( i - 3 ) ] = 1;
i = 0;
while( vis[ i ] )
++i;
return sg[ n ] = i;
}
int main(){
int n;
memset( sg, -1 , sizeof( sg ) );
while( scanf( "%d", &n ) != EOF ){
if( dfs( n ) ) printf( "1\n" );
else printf( "2\n" );
}
return 0;
}