LightOJ - 1247 Matrix Game (Nim博弈)题解
题意:
给一个矩阵,每一次一个玩家可以从任意一行中选任意数量的格子并从中拿石头(但最后总数要大于等于1),问你谁赢
思路:
一开始以为只能一行拿一个...
将每一行石子数相加就转化为经典的Nim博弈
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
const int N = 100000+5;
const int INF = 0x3f3f3f3f;
using namespace std;
int main() {
int T,m,n,a,Case = 1;
scanf("%d",&T);
while(T--){
scanf("%d%d",&m,&n);
int ans = 0;
for(int i = 0;i < m;i++){
int sum = 0;
for(int i = 0;i < n;i++){
scanf("%d",&a);
sum += a;
}
ans ^= sum;
}
if(ans == 0) printf("Case %d: Bob\n",Case++);
else printf("Case %d: Alice\n",Case++);
}
return 0;
}
LightOJ - 1247 Matrix Game (Nim博弈)题解的更多相关文章
- LightOJ 1186 Icreable Chess(Nim博弈)
You are given an n x n chess board. Only pawn is used in the 'Incredible Chess' and they can move fo ...
- LightOJ 1247 Matrix Game (尼姆博弈)
A - Matrix Game Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submi ...
- LightOJ 1253 Misere NIM(反NIM博弈)
Alice and Bob are playing game of Misère Nim. Misère Nim is a game playing on k piles of stones, eac ...
- nim博弈 LightOJ - 1253
主要是写一下nim博弈的理解,这个题有点奇怪,不知道为什么判断奇偶性,如果有大佬知道还请讲解一下. //nim博弈 //a[0]~a[i] 异或结果为k 若k=0 则为平衡态 否则为非平衡态 //平衡 ...
- codeforces 812E Sagheer and Apple Tree(思维、nim博弈)
codeforces 812E Sagheer and Apple Tree 题意 一棵带点权有根树,保证所有叶子节点到根的距离同奇偶. 每次可以选择一个点,把它的点权删除x,它的某个儿子的点权增加x ...
- POJ2234:Matches Game(Nim博弈)
Matches Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12325 Accepted: 7184 题目链 ...
- hdu2509Be the Winner(反nim博弈)
Be the Winner Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu1907John(反nim博弈)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hdu1730Northcott Game(nim博弈)
Northcott Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- table 的td 自适应事项
media的html结构,如果用display:table-cell实现, table { width: 100%; border-collapse: collapse; border: $bor; ...
- UITextField输入中文
[self.rightTF addTarget:self action:@selector(rightTFValueChange:) forControlEvents:UIControlEventEd ...
- [sh]sh最佳实战(含grep)
sh虐我千百遍,我待sh如初恋. sh复习资料 http://www.cnblogs.com/iiiiher/p/5385108.html http://blog.csdn.net/iiiiher/a ...
- [LeetCode] 513. Find Bottom Left Tree Value_ Medium tag: BFS
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 ...
- [LeetCode] 476. Number Complement_Easy tag: Bit Manipulation
这个题目思路就是比如101 的结果是010, 可以从111^101 来得到, 那么我们就需要知道刚好比101多一位的1000, 所以利用 while i <= num : i <<= ...
- 常用软件安装及VS插件工具
常用开发工具安装 开发环境 Visual Studio 2013 Microsoft SQL Server 2008 源代码管理 Git TortoiseGit GitScc Provider Cru ...
- android studio 错误: 编码GBK的不可映射字符
在模块的build.gradle中加入: tasks.withType(JavaCompile) { options.encoding = "UTF-8" } JavaCompil ...
- ShuffleElements(随机打乱数组中的元素)
给定一个数组,随机打乱数组中的元素,题意很简单直接上代码: package Array; import java.util.Arrays; import java.util.Collections; ...
- Java代码质量度量工具大阅兵
FindBugs FindBugs, a program which uses static analysis to look for bugs in Java code. It is free so ...
- apache 中 ServerAlias让多个域名绑定到同一空间
在apache的虚拟主机中,如果书写了.ServerAlias www.a2.com www.a3.com这样的语句,就可以给虚拟主机增加多个域名,而且这些域名都访问同一个站点. #Listen 81 ...