题目传送门:http://poj.org/problem?id=1740
这一次,打印了二维的情况,没能找出规律
可耻地看了题解:
如果有偶数堆,且石子个数相同的堆可以两两配对,则先手必败,因为不论先手怎么走,后手都可以走一样的步骤
其余的情况,先手都可以通过一次移动,达到上述的情况,即后手必败
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int MAXN = 10+9; int arr[MAXN],n; inline int read(){ char c=getchar(); int ret=0; while (c<'0'||c>'9') c=getchar(); while (c<='9'&&c>='0') ret=ret*10+c-'0',c=getchar(); return ret; } int main(){ while (n = read()) { for (int i=1;i<=n;i++) arr[i] = read(); sort(arr+1,arr+1+n); if (n%2) {cout<<1<<endl; continue;} int tag = 1; for (int i=1;i<=n;i+=2) if (arr[i] != arr[i+1]) {cout<<1<<endl; tag = 0; break;} if (tag) cout<<0<<endl; } return 0; }
Everything is very open and very clear explanation of issues. was truly information. Your website is very useful. Thanks for sharing.
Hey There. I found your blog using msn. This is an extremely well written article. I will be sure to bookmark it and return to read more of your useful info. Thanks for the post. I will certainly return.