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. 洛谷P5273 【模板】多项式幂函数 (加强版)

    题面 传送门 题解 这里最麻烦的问题就是它不保证\(A_0=1\) 如果\(A_0>1\),那么直接整个多项式乘上个\(A_0\)的逆元,最后输出答案的时候再把答案乘上\({A_0}^m\) 如 ...

  2. css3中的translate,transform,transition的区别

    translate:移动,transform的一个方法               通过 translate() 方法,元素从其当前位置移动,根据给定的 left(x 坐标) 和 top(y 坐标) ...

  3. 队列优化dijsktra(SPFA)的玄学优化

    转载:大佬博客 最近想到了许多优化spfa的方法,这里想写个日报与大家探讨下 前置知识:spfa(不带任何优化) 由于使用较多 STLSTL ,本文中所有代码的评测均开启 O_2O2​ 优化 对一些数 ...

  4. Review notes

  5. selenium(python)登录时账号密码错误提示语

    selenium(python)登录时账号密码错误提示语的获取 可以用text

  6. maven 打包 源代码

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-sourc ...

  7. 进阶篇:2.1)DFMA实施障碍和关键

    本章目的:了解DFMA实施障碍与关键. 1.实施的障碍 面向制造和装配的产品开发能够降低产品成本.提高产品质量.缩短产品开发周期,但是,由于传统产品开发思想和各种条件的限制,实施面向制造和装配的产品开 ...

  8. 899. Orderly Queue

    A string S of lowercase letters is given.  Then, we may make any number of moves. In each move, we c ...

  9. 使用Jmeter进行http接口性能测试(转载)

    在进行网页或应用程序后台接口开发时,一般要及时测试开发的接口能否正确接收和返回数据,对于单次测试,Postman插件是个不错的Http请求模拟工具. 但是Postman只能模拟单客户端的单次请求,而对 ...

  10. (转)nginx 常用模块整理

    原文:http://blog.51cto.com/arm2012/1977090 1. 性能相关配置 worker_processes number | auto: worker进程的数量:通常应该为 ...