Being a Good Boy in Spring Festival HDU - 1850
现在我们不想研究到底先手为胜还是为负,我只想问大家:
——“先手的人如果想赢,第一步有几种选择呢?”
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
由于一次只能对一堆牌进行操作,假设我 操作第i堆牌(a张),抽出x张。
那么其余n-1堆牌的异或值是固定为b.
那么 (a - x)^ b == 0 时,对手必败。
到此可能有人觉得必须历遍所有a求出那个值x满足条件。其实不必要
由上式可知x只有唯一取值
而且 一个数 与 b 异或等于 0 即表明 这个数等于b.
所以反过来我们可以求出b, 令 a - x = b ;
只要b满足 b < a; 即能构造出x使得 (a - x)^ b == 0 时,对手必败!
而且经过举例,我发现总的异或值bns异或a后的结果正好是b的值
AC Code:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int vis[];
int main(){
int n;
while(cin>>n&&n){
int cnt=,bns=;
for(int i=;i<n;i++){
cin>>vis[i];
bns^=vis[i];
}
for(int i=;i<n;i++){
int ans=bns;
ans^=vis[i];
if(ans<vis[i]) cnt++;
}
cout<<cnt<<endl;
}
Being a Good Boy in Spring Festival HDU - 1850的更多相关文章
- hdu 1850 Being a Good Boy in Spring Festival(Nimm Game)
题意:Nimm Game 思路:Nimm Game #include<iostream> #include<stdio.h> using namespace std; int ...
- HDU.1850 being a good boy in spring festival (博弈论 尼姆博弈)
HDU.1850 Being a Good Boy in Spring Festival (博弈论 尼姆博弈) 题意分析 简单的nim 博弈 博弈论快速入门 代码总览 #include <bit ...
- HDU 1850 Being a Good Boy in Spring Festival (Nim博弈)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- HDU 1850 Being a Good Boy in Spring Festival(博弈·Nim游戏)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- HDUOJ-------Being a Good Boy in Spring Festival
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- HDU1850 Being a Good Boy in Spring Festival
/* HDU1850 Being a Good Boy in Spring Festival http://acm.hdu.edu.cn/showproblem.php?pid=1850 博弈论 尼姆 ...
- Being a Good Boy in Spring Festival
Being a Good Boy in Spring Festival Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一 ...
- HDU1850 Being a Good Boy in Spring Festival(博弈)
Being a Good Boy in Spring Festival Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I ...
- Being a Good Boy in Spring Festival(尼姆博弈)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
随机推荐
- (转)开源项目miaosha(下)
石墨文档:https://shimo.im/docs/2XlwliBQAYsKCHbq/ (二期)20.开源秒杀项目miaosha解读(下) [课程20]jmeter.xmind81.5KB [课程2 ...
- 题解——洛谷P3275 [SCOI2011]糖果
一道条件非常多的差分约束 把\( a < b \)转化为\( a-b \le -1\)就可做了 \( a>b \)的情况同理 若有负环则无解输出-1 注意本题中要求每个人都有糖果 所以假设 ...
- %lld 和 %I64d的区别
参考一个博客的链接:https://blog.csdn.net/thunders01/article/details/38879553
- HDU 5607 graph(矩阵乘法)
题意 在一个 \(n\) 个节点 \(m\) 条边的有向图上随机游走,有 \(Q\) 个询问,每次给定一个起点 \(u\) 和步数 \(K\) ,每次回答最后停在每个节点的概率. \(1 \leq n ...
- powerdesigner反转数据库的设计图
PowerDesigner导入sql文件 1:点击 2:弹出该页面,点击确定 3:弹出一下页面,点击下面按钮选择文件 4:点击确定完成 二 .表转换为中文的执行脚本及步骤 执行脚本为:Option E ...
- algorithm.sty not found error in LaTeX 解决方法
参考: algorithm.sty not found error in LaTeX algorithm.sty not found error in LaTeX 解决方法 错误日志: LaTeX E ...
- js点击显示隐藏
这个栗子…… 可以不吃,先预设一个变量表示div的状态,例子中0是显示的,一开始是隐藏的.当点击时判断状态是显示0的还是隐藏1的:如果是显示的就把div隐藏,再把变量改变为1.再次点击时把会判断到变量 ...
- JMeter 生成CSV文件中文变乱码的问题
在通过BeanShell 生成CSV文件时,写入的中文字符默认情况会变成乱码. //默认情况生成的文件是asii编码.fileName = “c:\test.csv";fos = new F ...
- node.js模块本地代理模块(将自己本机/局域网)服务 代理到外网可以访问
npm 模块 localtunnel模块可以. lt --port 7000 其中7000是本地服务端口 会分配一个动态的url. 局域网中查看本地ip用ifconfg 或者在系统偏好设置里面查看网 ...
- wxss与rpx
WXSS(WeiXin Style Sheets)是一套样式语言,用于描述 WXML 的组件样式. WXSS 用来决定 WXML 的组件应该怎么显示. 为了适应广大的前端开发者,WXSS 具有 CSS ...