题意:已知异或和为0为必败态,异或和不为0为必胜态,问你有几种方法把开局从当前状态转为必败态。

思路:也就是说,我们要选一堆石头,然后从这堆石头拿走一些使剩下的石碓异或和为0。那么只要剩下石堆的异或和小于选中石堆的大小,那么肯定能从选中石堆中找出一定数目和剩下的石堆异或后归零。

代码:

#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define eps 1e-9
typedef long long ll;
const int maxn = + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
ll a[maxn];
int main(){
int n;
ll ans;
while(scanf("%d", &n) && n){
ans = ;
for(int i = ; i <= n; i++){
scanf("%lld", &a[i]);
ans ^= a[i];
}
int tot = ;
for(int i = ; i <= n; i++){
if((ans ^ a[i]) < a[i]) tot++;
}
printf("%d\n", tot);
}
return ;
}

POJ 2975 Nim(博弈)题解的更多相关文章

  1. POJ 2234 Nim博弈

    思路: nim博弈裸题 xor一下 //By SiriusRen #include <cstdio> using namespace std; int n,tmp,xx; int main ...

  2. poj 2975 Nim(博弈)

    Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5232   Accepted: 2444 Description N ...

  3. POJ 2975 Nim 尼姆博弈

    题目大意:尼姆博弈,求先手必胜的情况数 题目思路:判断 ans=(a[1]^a[2]--^a[n]),求ans^a[i] < a[i]的个数. #include<iostream> ...

  4. POJ 2975 Nim(博弈论)

    [题目链接] http://poj.org/problem?id=2975 [题目大意] 问在传统的nim游戏中先手必胜策略的数量 [题解] 设sg=a1^a1^a3^a4^………^an,当sg为0时 ...

  5. poj -2975 Nim

      Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4312   Accepted: 1998 Description ...

  6. [原博客] POJ 2975 Nim 统计必胜走法个数

    题目链接题意介绍了一遍Nim取石子游戏,可以看上一篇文章详细介绍.问当前状态的必胜走法个数,也就是走到必败状态的方法数. 我们设sg为所有个数的Xor值.首先如果sg==0,它不可能有必胜走法,输出0 ...

  7. poj 2975 Nim 博弈论

    令ans=a1^a2^...^an,如果需要构造出异或值为0的数, 而且由于只能操作一堆石子,所以对于某堆石子ai,现在对于ans^ai,就是除了ai以外其他的石子 的异或值,如果ans^ai< ...

  8. POJ 2975 Nim(普通nim)

    题目链接 #include<iostream> #include<cstdio> using namespace std; int main() { ]; int sum,cn ...

  9. POJ 2234 Matches Game(Nim博弈裸题)

    Description Here is a simple game. In this game, there are several piles of matches and two players. ...

随机推荐

  1. express 默认模板引擎

    使用express -t ejs microblog创建出来的居然不是ejs项目,而是jade项目.现在的版本已经没有-t这个命令了,改为express -e microblog.运行完之后,根据提示 ...

  2. promise VS future

    Future and Promise are the two separate sides of an asynchronous operation. promise is used by the & ...

  3. NYOJ 587 blockhouses 【DFS】

    blockhouses 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 Suppose that we have a square city with straigh ...

  4. listview点击控件显示EditText,键盘弹出消失的解决方法:

    1.软键盘弹出后消失解决方法 AndoridManifet 在activity中添加: android:windowSoftInputMode="adjustPan" 2.使用方式 ...

  5. MySql操作语句集锦

    Windows服务 -- 启动MySQL    net start mysql-- 创建Windows服务    sc create mysql binPath= mysqld_bin_path(注意 ...

  6. 005-spring boot 2.0.4-jdbc升级

    一.概述 Springboot2默认数据库连接池选择了HikariCP为何选择HikariCP理由一.代码量理由二.口碑理由三.速度理由四.稳定性理由五.可靠性HikariCP为什么这么快优化并精简字 ...

  7. 虚拟机VMware的网络设置出了问题会导致很多莫名的错误

    邪门地CentOS内软件安装失败问题:Xshell与虚拟机的各种连接失败:CentOS下eth0没显示ip地址. 这些原因竟然是一个,虚拟机VMware的网络设置出了问题.     恢复初始设置即可.

  8. POJ3169:Layout(差分约束)

    http://poj.org/problem?id=3169 题意: 一堆牛在一条直线上按编号站队,在同一位置可以有多头牛并列站在一起,但编号小的牛所占的位置不能超过编号大的牛所占的位置,这里用d[i ...

  9. [LeetCode] 301. Remove Invalid Parentheses_Hard tag:BFS

    Remove the minimum number of invalid parentheses in order to make the input string valid. Return all ...

  10. 为什么size_t重要?

    参见 http://en.cppreference.com/w/cpp/types/size_t size_t其实与uintptr_t一个道理.就是一个东西.指针其实就是寻址,与地址总线位数一致,编译 ...