Game

Time Limit: 10000ms
Case Time Limit: 10000ms
Memory Limit: 65536KB
 
64-bit integer IO format: %lld      Java class name: Main
Alice and Bob invented a new game again, as they usually did.
The rule of the new game is quite simple. There is an n*n matrix and at the very beginning of the game, some of ceil contain stone, and others contain nothing. Then they take turns (Alice first) to play the game.
Each time one person should choose two empty ceils which are on the same line, and the number of their columns’ difference is exactly 2(which means the absolute value of difference is 2). And then the people should put stones on each of the two ceil. The game ends when one people cannot do the operation above and thus lose the game.
Here's the problem: Who will win the game if both use the best strategy? Find it out quickly, before they get bored of the game again!
 
 

Input

The first line contains a single integer T, indicating the number of test cases.
The first line of each test case contains an integer n (1<=n<=1000), and n lines follow. Each line contains n integers 0 or 1, which means there exist a stone or not (1 means exist).
 

Output

For each test case, output the case number first, then “Alice” if Alice will win otherwise output “Bob”.
 

Sample Input

2
3
0 0 0
0 0 0
1 0 0
4
0 0 0 1
1 0 1 0
1 1 1 1
1 0 1 0
 

Sample Output

Case 1: Bob
Case 2: Alice

这道题,是一道博弈题。

每一行是可以单独考虑的,这个是很好理解的。

奇数和偶数行也是可以单独考虑的。推一推。

"1"的存在,用来分割他们进行讨论。

题目的转化为 n 堆石头子,每次从每一堆取出2个连续堆的方案。

这里就简单了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; int SG[];
bool use[];
void prepare()
{
int i,j;
SG[]=;SG[]=;
for(i=;i<=;i++)
{
memset(use,false,sizeof(use));
for(j=;j<i;j++)
{
use[ (SG[j-] ^ SG[i-j-]) ]=true;
}
for(j=;;j++)
if(use[j]==false)
{
SG[i]=j;
break;
}
}
}
int main()
{
int T,n,ans[],t;
int i,j,x,XOR;
prepare();
scanf("%d",&T);
for(t=;t<=T;t++)
{
scanf("%d",&n);
XOR=;
for(i=;i<=n;i++)
{
ans[]=;ans[]=;
for(j=;j<=n;j++)
{
scanf("%d",&x);
if(x==)
ans[j%]++;
else
{
XOR=XOR^SG[ans[j%]];
ans[j%]=;
}
}
XOR=XOR^SG[ans[]];
XOR=XOR^SG[ans[]];
}
printf("Case %d: ",t);
if(XOR==)
printf("Bob\n");
else printf("Alice\n");
}
return ;
}

SG[ ] 使用map。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
using namespace std; int SG[];
map<int,int>Q;
void prepare()
{
int i,j,k,s;
SG[]=;SG[]=;
for(i=;i<=;i++)
{
while(!Q.empty())
{
Q.clear();
}
for(s=,j=;j<i;j++)
{
k=(SG[j-] ^ SG[i-j-]);
Q[k]=s++;
}
for(j=;;j++)
if(Q.find(j)==Q.end())
{
SG[i]=j;
break;
}
}
}
int main()
{
int T,n,ans[],t;
int i,j,x,XOR;
prepare();
scanf("%d",&T);
for(t=;t<=T;t++)
{
scanf("%d",&n);
XOR=;
for(i=;i<=n;i++)
{
ans[]=;ans[]=;
for(j=;j<=n;j++)
{
scanf("%d",&x);
if(x==)
ans[j%]++;
else
{
XOR=XOR^SG[ans[j%]];
ans[j%]=;
}
}
XOR=XOR^SG[ans[]];
XOR=XOR^SG[ans[]];
}
printf("Case %d: ",t);
if(XOR==)
printf("Bob\n");
else printf("Alice\n");
}
return ;
}

bnu Game 博弈。的更多相关文章

  1. bnu 4353 删格游戏(博弈)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=4353 [题意]:每次选择一个小格后,该小格的右上部分就全被删去了,且要求每次至少删去一个格子,选中左 ...

  2. hdu----(1849)Rabbit and Grass(简单的尼姆博弈)

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 5754 Life Winner Bo 组合博弈

    Life Winner Bo Problem Description   Bo is a "Life Winner".He likes playing chessboard gam ...

  4. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  5. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

  6. 51nod1072(wythoff 博弈)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1072 题意: 中文题诶~ 思路: 博弈套路是有的, 找np局 ...

  7. ACM: NBUT 1107 盒子游戏 - 简单博弈

     NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  8. 【转】ACM博弈知识汇总

    博弈知识汇总 转自:http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍 ...

  9. Uva 10891 经典博弈区间DP

    经典博弈区间DP 题目链接:https://uva.onlinejudge.org/external/108/p10891.pdf 题意: 给定n个数字,A和B可以从这串数字的两端任意选数字,一次只能 ...

随机推荐

  1. jquery源码解析:expando,holdReady,ready详解

    jQuery的工具方法,其实就是静态方法,源码里面就是通过extend方法,把这些工具方法添加给jQuery构造函数的. jQuery.extend({       //当只有一个对象时,就把这个对象 ...

  2. java集合类学习笔记之LinkedHashMap

    1.简述 LinkedHashMap是HashMap的子类,他们最大的不同是,HashMap内部维护的是一个单向的链表数组,而LinkedHashMap内部维护的是一个双向的链表数组.HashMap是 ...

  3. Maven web项目(简单的表单提交) 搭建(eclipse)

    我们将会搭建一个,基于Maven管理的,具有简单的表单提交功能的web项目,使用DAO--service--WEB三层结构,服务器使用Tomcat 1 项目基本结构的搭建 左上角File---> ...

  4. [Java]去除html中的标签或者元素属性(正则表达式)

    后台的数据库中某个字段是富文本框输入的 带有Html的标签 ,去掉标签后返回给前台 1.去掉Html 标签的代码 //过滤html标签 Pattern p_html = Pattern.compile ...

  5. 达人篇:3.1.3)FAI 首件检验

    本章目的:了解FAI. 1)定义: FAI: First Article Inspection Report . 汉语译作:首件全尺寸检验报告. 2)目的 制作FAI报告是为了检查成型后的产品尺寸是否 ...

  6. module.exports,exports,export和export default,import与require区别与联系

    还在为module.exports.exports.export和export default,import和require区别与联系发愁吗,这一篇基本就够了! 一.首先搞清楚一个基本问题: modu ...

  7. HTTP请求的常用方法有哪些

    HTTP请求的常用方法有:GET方法.POST方法.HEAD方法.PUT方法.DELETE方法.CONNECT方法.OPTIONS方法.TRACE方法.下面本篇文章就给大家介绍具体介绍一下HTTP请求 ...

  8. VUE 监听局部滚动 设置ICON的位置跟随

    效果图如下: 目的: 为了让 + 号与 - 号跟随在当前 tr 的前边 第一步: 当tr指针经过时获取tr的相对位置 HTML JS 第二步:给滚动的div元素添加滚动事件获取滚动的高度 最后:设置I ...

  9. 转 $.ajax()方法详解

    1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如 ...

  10. Ubuntu 16.04 compare 软件安装

    1软件官网 http://www.scootersoftware.com/download.php?zz=kb_linux_install 2.打开上述网址可看到安装信息 终端安装方式: wget h ...