Fliping game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 46    Accepted Submission(s): 35

Problem Description
Alice and Bob are playing a kind of special game on an N*M board (N rows, M columns). At the beginning, there are N*M coins in this board with one in each grid and every coin may be upward or downward freely. Then they take turns to choose a rectangle (x1, y1)-(n, m) (1 ≤ x1≤n, 1≤y1≤m) and flips all the coins (upward to downward, downward to upward) in it (i.e. flip all positions (x, y) where x1≤x≤n, y1≤y≤m)). The only restriction is that the top-left corner (i.e. (x1, y1)) must be changing from upward to downward. The game ends when all coins are downward, and the one who cannot play in his (her) turns loses the game. Here's the problem: Who will win the game if both use the best strategy? You can assume that Alice always goes first.
 
Input
The first line of the date is an integer T, which is the number of the text cases.
Then T cases follow, each case starts with two integers N and M indicate the size of the board. Then goes N line, each line with M integers shows the state of each coin, 1<=N,M<=100. 0 means that this coin is downward in the initial, 1 means that this coin is upward in the initial.
 
Output
For each case, output the winner’s name, either Alice or Bob.
 
Sample Input
2
2 2
1 1
1 1
3 3
0 0 0
0 0 0
0 0 0
 
Sample Output
Alice
Bob
 
Source
 
Recommend
zhuyuanchen520
 

和翻硬币那个很类似。

简单的博弈,找规律发现只有最右下角的SG值为1,其余的都为0;

所以所有1的SG值异或的结果取决于最右下角的。

只有右下角为1,输出Alice,否则输出Bob

/*
* Author:kuangbin
* 1011.cpp
*/ #include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <math.h>
using namespace std; int main()
{
//freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int T;
int a;
scanf("%d",&T);
while(T--)
{
int sum = ;
int n,m;
scanf("%d%d",&n,&m);
for(int i = ;i <= n;i++)
for(int j = ;j <= m;j++)
{
scanf("%d",&a);
}
if(a)printf("Alice\n");
else printf("Bob\n");
}
return ;
}

HDU 4642 Fliping game (2013多校4 1011 简单博弈)的更多相关文章

  1. HDU 4678 Mine (2013多校8 1003题 博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  2. HDU 4665 Unshuffle (2013多校6 1011 )

    Unshuffle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  3. HDU 4705 Y (2013多校10,1010题,简单树形DP)

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

  4. HDU 4704 Sum (2013多校10,1009题)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

  5. HDU 4699 Editor (2013多校10,1004题)

    Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  6. HDU 4696 Answers (2013多校10,1001题 )

    Answers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  7. HDU 4690 EBCDIC (2013多校 1005题 胡搞题)

    EBCDIC Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Su ...

  8. HDU 4681 String(2013多校8 1006题 DP)

    String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Subm ...

  9. HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

随机推荐

  1. Linux时间子系统之八:动态时钟框架(CONFIG_NO_HZ、tickless)【转】

    转自:http://blog.csdn.net/droidphone/article/details/8112948 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[-] 数据结 ...

  2. grep常见操作整理(更新)

    提取邮箱和URL [root@test88 ~]# cat url_email.txt root@gmail.com,http://blog.peter.com,peter@qq.com [root@ ...

  3. JQuery判断一个元素下面是否有内容或者有某个标签

    网站开发时,我们时常需要把没有内容的标签隐藏或者去掉.在用JQ有两种好的解决办法: 一.判断文本是否为空 var jqObj = $(this);if(jqObj.text().trim()){ // ...

  4. leetcode 之Reorder List(25)

    找到中间结点,将后半部分反转接入即可. ListNode *reoderList(ListNode* head) { if (head == nullptr || head->next == n ...

  5. C++11空指针: nullptr

    参考[C++11]新特性--引入nullptr NULL 在C++中, 经常会用到空指针, 一般用NULL表示空指针, 但是NULL却是这样定义的 #ifndef NULL #ifdef __cplu ...

  6. ELK日志处理

    ELK的工作原理: 使用多播进行机器发现同一个集群内的节点,并汇总各个节点的返回组成一个集群,主节点要读取各个节点的状态,在关键时候进行数据的恢复,主节点会坚持各个节点的状态,并决定每个分片的位置,通 ...

  7. IA32系统级架构总览(二)

    系统级架构由寄存器.数据结构.指令组成,这些设计对基本的系统级别的操作提供了支持,比如:内存管理.终端与异常处理.任务管理.多进程控制等. 我们先来看一看寄存器与数据结构的总汇图:现在你可能看不懂,不 ...

  8. 寻找与网页内容相关的图片(二)reddit的做法

    正如前文所述,内容聚合网站,比如新浪微博.推特.facebook等网站对于网页的缩略图是刚需.为了让分享的内容引人入胜,网页的图片缩略图是必不可少的.年轻人的聚集地.社交新闻网站reddit也是一个这 ...

  9. 探索sklearn | 鸢尾花数据集

    1 鸢尾花数据集背景 鸢尾花数据集是原则20世纪30年代的经典数据集.它是用统计进行分类的鼻祖. sklearn包不仅囊括很多机器学习的算法,也自带了许多经典的数据集,鸢尾花数据集就是其中之一. 导入 ...

  10. AC日记——聪明的质监员 洛谷 P1314

    聪明的质监员 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 #define l ...