就是如果放了一个在某个位置,那么就不能放他旁边的四个了(左边两个,右边两个)。如下图,如果A在红画了X,如果B在绿画了X,那么A再在蓝画了X,A就能赢。
/*
AUTHOR: Su Jiao
DATE: 2010-6-19
DESCRIPTION:
http://acm.pku.edu.cn/JudgeOnline/problem?id=3537
*/
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <vector>
using std::vector;
class Application
{
int n;
vector<int> _sg;
int SG(int x)
{
if (x<0) return 0;
if (_sg[x]!=-1) return _sg[x];
else
{
vector<bool> found(n+1,false);
for (int i=1;i<=x;i++)
found[SG(i-2–1)^SG(x-i-2)]=true;
for (int i=0;i<=n;i++)
if (!found[i]) return _sg[x]=i;
}
}
public:
Application()
{
std::ios::sync_with_stdio(false);
}
int run()
{
cin>>n;
_sg.resize(n+1,-1);
if (SG(n)) cout<<1<<endl;
else cout<<2<<endl;
return 0;
}
};
int main()
{
Application app;
return app.run();
}