天天看点

求到达必败态的方法数 ZOJ 3067 Nim

/*
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3067

题意:求胜态到达必败态的方法数

Nim
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int s[1005];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
#endif
	int n;
	while(scanf("%d", &n), n){
		int res = 0;
		for(int i=0; i<n; i++){
			scanf("%d", &s[i]);
			res ^= s[i];
		}
		if(res){
			int num = 0;
			for(int i=0; i<n; i++)
				if( (res^s[i]) <= s[i])// 要注意(),表示对s[i]的操作可以到达必败态
					num++;
			printf("%d\n", num);
		}else
			printf("0\n");
	}
	return 0;
}