bnu Game 博弈。
Game
Input
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
Sample Input
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 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 博弈。的更多相关文章
- bnu 4353 删格游戏(博弈)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=4353 [题意]:每次选择一个小格后,该小格的右上部分就全被删去了,且要求每次至少删去一个格子,选中左 ...
- hdu----(1849)Rabbit and Grass(简单的尼姆博弈)
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5754 Life Winner Bo 组合博弈
Life Winner Bo Problem Description Bo is a "Life Winner".He likes playing chessboard gam ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
- 51nod1072(wythoff 博弈)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1072 题意: 中文题诶~ 思路: 博弈套路是有的, 找np局 ...
- ACM: NBUT 1107 盒子游戏 - 简单博弈
NBUT 1107 盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- 【转】ACM博弈知识汇总
博弈知识汇总 转自:http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍 ...
- Uva 10891 经典博弈区间DP
经典博弈区间DP 题目链接:https://uva.onlinejudge.org/external/108/p10891.pdf 题意: 给定n个数字,A和B可以从这串数字的两端任意选数字,一次只能 ...
随机推荐
- codis__通用的使用模式
1,按功能模块分成不同的productName 参照 sample_user, sample_dynamic (见附件) sample_user.tar.gz,sample_dynamic.tar.g ...
- UDF-java获取名字中的姓
1.使用方法 在hive中加载jar包,调用udf函数 #从名字中获取姓 add jar ${scriptDir}/GetLastNameUDF.jar; create temporary funct ...
- P4097 [HEOI2013]Segment 李超线段树
$ \color{#0066ff}{ 题目描述 }$ 要求在平面直角坐标系下维护两个操作: 在平面上加入一条线段.记第 i 条被插入的线段的标号为 i 给定一个数 k,询问与直线 x = k 相交的线 ...
- sqlalchemy中使用event设置条件触发短信与邮件通知
一.原因 近期在做短信与邮件通知系统.使用到了这一块.例如,当订单完成以后进行邮件短信的通知.虽然可以采用直接调用接口的方式实现,但有几个原因让我希望使用条件触发的方式 1.由于系统中支持线上线下以及 ...
- 2016级算法第五次上机-A.Beihang Collegiate Pronunciation Contest 2017
1065 Beihang Collegiate Pronunciation Contest 2017 思路 在字符串中不断做匹配 找到一个匹配就输出 时间复杂度\(O(n)\) ps.模式串是定长的, ...
- Linux进程间通信——使用System V 消息队列
消息队列 消息队列提供了一种从一个进程向另一个进程发送一个数据块的方法. 每个数据块都被认为含有一个类型,接收进程可以独立地接收含有不同类型的数据结构.我们可以通过发送消息来避免命名管道的同步和阻塞问 ...
- 搭建自己的pypi私有源服务器
最简单的方式: pypiserver – minimal pypi server, easy to install & use 1.安装pypiserver:pip install pypis ...
- [HDU4035] Maze(概率DP)
HDU4035 有\(n\)个房间 , 由\(n-1\)条隧道连通起来 , 实际上就形成了一棵树 , 从结点\(1\)出发 , 开始走 , 在每个结点\(i\)都有\(3\)种可能 : \(1.\)被 ...
- system命令
服务查看 查看所有服务运行状态: service --status-all chkconfig --list 查看单个服务的运行状态 service sshd status 查看启动状态,是否开机自动 ...
- MySQL授权命令grant的详细使用方法
2019-01-07 转自 https://www.cnblogs.com/crxis/p/7044582.html 本文实例,运行于 MySQL 5.0 及以上版本. MySQL 赋予用户权限命令的 ...