HDU 1907 John (Nim博弈 模板)
来源:互联网 发布:最短路径的算法 编辑:程序博客网 时间:2024/05/21 14:07
题意:约翰和他哥哥玩一个游戏,n堆糖果,每堆糖果Ai个,约翰先拿任意个同一种的糖果,然后轮到他的哥哥拿任意个同一种的糖果。谁最后拿完最后一堆的最后一个糖果,谁获胜。
Nim博弈的模板题目。
#include <iostream>#include <algorithm>#include <cmath>#include <cstdio>using namespace std;int main(){ int t; scanf("%d",&t); while(t--) { int n,num=0,a[50],flag=0; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); if(a[i]!=1) num++; } if(num==0)//第一种情况 { if(n%2==0) flag=1; } else if(num==1) //第二种情况 flag=1; else //第三种情况 { int nim=a[1]; for(int i=2;i<=n;i++) nim=nim^a[i]; if(nim!=0) flag=1; } printf("%s\n",flag==1?"John":"Brother"); } return 0;}
阅读全文
0 0
- HDU 1907 John (Nim博弈 模板)
- HDU 1907 John(Nim博弈)
- hdu 1907 John(Nim博弈)
- HDU 1907 John Nim博弈
- HDU 1907 Nim博弈 John
- HDU 1907 John (Nim博弈)
- HDU 1907 John nim博弈变形
- HDU(2509) Be the Winner /HDU(1907) John (Nim 博弈)
- HDOJ 1907 John nim博弈
- HDOJ 1907 John (nim博弈)
- HDU 2509 Be the Winner && HDU 1907 John (Nim博弈变形)
- [博弈]HDU 1907 John
- (hdu 1907)John (Misère Nim,Nim博弈的变形)
- HDOJ 1907 John anti-nim博弈
- HDU 1907 John ( Nim Game )
- hdu 1907 John(anti-nim)
- HDU 1907 John(Nim game)
- hdu 1907 John(尼姆博弈)
- NDK的基础教程 四 动态注册
- TypeError: Expected int32, got list containing Tensors of type '_Message' instead.解决方法
- tensorflow 使用正则化
- Hyper-V 虚拟机虚拟网卡慢问题解决方案
- 多态相关(虚函数,覆盖,纯虚函数,抽象类)
- HDU 1907 John (Nim博弈 模板)
- JQuery学习笔记(One)
- 一种排序
- 关于Unity3D中使用SQLite数据库发生的几种常见错误(适用新手)
- MYSQL常用命令
- c++后台开发需要掌握哪些知识
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- PCI、PCI-x,PCI-E兼容以及他们之间的区别详细图解
- 深度学习基础知识(4):卷积层的实现