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

  1. /*
  2. * Author:kuangbin
  3. * 1011.cpp
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <algorithm>
  8. #include <string.h>
  9. #include <iostream>
  10. #include <map>
  11. #include <vector>
  12. #include <queue>
  13. #include <set>
  14. #include <string>
  15. #include <math.h>
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20. //freopen("in.txt","r",stdin);
  21. // freopen("out.txt","w",stdout);
  22. int T;
  23. int a;
  24. scanf("%d",&T);
  25. while(T--)
  26. {
  27. int sum = ;
  28. int n,m;
  29. scanf("%d%d",&n,&m);
  30. for(int i = ;i <= n;i++)
  31. for(int j = ;j <= m;j++)
  32. {
  33. scanf("%d",&a);
  34. }
  35. if(a)printf("Alice\n");
  36. else printf("Bob\n");
  37. }
  38. return ;
  39. }

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内核启动分析(3)

    主要分析do_basic_setup函数里面的do_initcalls()函数,这个函数用来调用所有编译内核的驱动模块中的初始化函数. static void __init do_initcalls( ...

  2. Django2.0如何配置urls文件

    刚开始学django,创建的第一个工程无法启动,后来发现是由于教程是针对较低版本的Django,我用的是Django2.0和Python3.6,两个都是发文为止的最新版本,urls文件设置方法和旧版本 ...

  3. win10出现"win10系统即将过期,请激活"的处理办法

    当打开电脑时,出现"你的win10系统即将过期,请前往激活”的提示.上网查了解决方案,避免以后在出现这样的情况,现将解决步骤整理如下: 1.下载KMSpico激活软件,百度网盘下载链接如下: ...

  4. JVM字节码执行引擎和动态绑定原理

    1.执行引擎 所有Java虚拟机的执行引擎都是一致的: 输入的是字节码文件,处理过程就是解析过程,最后输出执行结果. 在整个过程不同的数据在不同的结构中进行处理. 2.栈帧 jvm进行方法调用和方法执 ...

  5. LeetCode解题报告—— Rotate List & Set Matrix Zeroes & Sort Colors

    1. Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. Exam ...

  6. JS将日期转换为yyyy-MM-dd HH:mm:ss

    //格式化后日期为:yyyy-MM-dd HH:mm:ss function FormatAllDate(sDate) { var date = new Date(sDate); var sepera ...

  7. es6数组必看太实用了

    随着前后分离,前端人员也要写大量的逻辑代码,es5很多地方尤其是数据工具大拿数组,很多时候都是捉襟见肘. 继而,es6为我们扩展了很多good的工具和方法,让我们一起学习es6吧. 1原型方法from ...

  8. macos不能打开windows samba共享问题(转载)

    转自:https://www.macx.cn/thread-2095377-1-1.html?mod=viewthread&tid=2095377&extra=page%253D1&a ...

  9. 转:西部数据NAS设备hack

    通过该文学习一下常见硬件web漏洞.重点关注一下几个方面: 1.登录验证代码: 2.文件上传代码: 3.system/exec/popen等是否存在注入可能: 4.调用二进制文件: 5.未登陆可以访问 ...

  10. 洛谷P2520向量

    题目传送门 看到数据范围其实就可以确定这是一道结论题. 首先分析,给定你的向量的两个坐标a,b有八种组合方式可以用,但实际上整理一下可以得出实际上只有五种,x/y ±2a,x/y ±2b,x+a,y+ ...