这道题和上一个差不多,就是尼姆博弈的应用,属于基础的尼姆博弈,除了判断是否是胜利外,还要输出胜态下第一步的可走的步数,即需要和原来的值相异或
题目:
小游戏:桌子上有M堆扑克牌;每堆牌的数量分别为Ni(i=1…M);两人轮流进行;每走一步可以任意选择一堆并取走其中的任意张牌;桌子上的扑克全部取光,则游戏结束;最后一次取牌的人为胜者。
现在我们不想研究到底先手为胜还是为负,我只想问大家:
——“先手的人如果想赢,第一步有几种选择呢?”
现在我们不想研究到底先手为胜还是为负,我只想问大家:
——“先手的人如果想赢,第一步有几种选择呢?”
Input
输入数据包含多个测试用例,每个测试用例占2行,首先一行包含一个整数M(1<M<=100),表示扑克牌的堆数,紧接着一行包含M个整数Ni(1<=Ni<=1000000,i=1…M),分别表示M堆扑克的数量。M为0则表示输入数据的结束。
Output
如果先手的人能赢,请输出他第一步可行的方案数,否则请输出0,每个实例的输出占一行。
Sample Input
3 5 7 9 0
Sample Output
1
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
int min(int a, int b)
{
if(a<=b)
return a;
return b;
}
int max(int a, int b)
{
if(a>=b)
return a;
return b;
}
double min(double a, double b)
{
if(a<=b)
return a;
return b;
}
double max(double a, double b)
{
if(a>=b)
return a;
return b;
}
int main()
{
int m;
int s[110];
while(cin >> m)
{
if(m==0)
break;
int ans = 0;
int cnt = 0;
for(int i = 0; i < m; ++i)
{
cin >> s[i];
ans ^= s[i];
}
if(ans==0)
cout << 0<<endl;
else
{
for(int j = 0; j < m; ++j)
{
int k = ans^s[j];
if(k<s[j])
cnt++;
}
cout << cnt <<endl;
}
}
return 0;
}
努力努力......