5754Life Winner Bo
给定一个n*m的矩阵,有四种棋子(国际象棋的王,王后,骑士,车)。起点在(1,1)先走到(n,m)获胜。
分析:车是nim博弈。王后是威佐夫博弈。王和骑士写两个1000*1000的预处理即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=;
int f[N][N],g[N][N];
void deal1()
{
int i,j;
f[][]=;
for(i=;i<=;i++)
for(j=;j<=;j++)
{ if(i==&&j==)continue;
else
{
f[i][j]=;
if(i>&&f[i-][j]==)f[i][j]=;
if(j>&&f[i][j-]==)f[i][j]=;
if(i>&&j>&&f[i-][j-]==)f[i][j]=;
}
}
} void deal2()
{
int i,j,d,e;
g[][]=;g[][]=-;
for(i=;i<=;i++)g[][i]=g[i][]=-;
for(i=;i<=;i++)
for(j=;j<=;j++)
{
if(j==&&i==)continue;
else
{
d=;e=;
if(i>)d++;if(j>)d++;
if(i>&&g[i-][j-]==)e++;
if(j>&&g[i-][j-]==)e++;
if(d==e)g[i][j]=;//所有的后继都为必胜,则它为必败态
else
{
if((j>&&g[i-][j-]==)||(i>&&g[i-][j-]==))
g[i][j]=;//后继有一个必败态,则它为必胜态
else
g[i][j]=-;//不是必胜态或必败态那么这个位置不满足条件
}
} }
}
int main()
{ int i,x,n,m,t,xo;
scanf("%d", &t);
deal1();deal2();
while (t--) {
scanf("%d%d%d", &x, &n, &m);
if (x==) {
if (f[n][m]==) printf("B\n");
else printf("G\n");
} else if (x==) {
xo=(n-)^(m-); //因为第一个位置是(1,1),不是(0,0);
if (xo) printf("B\n");
else printf("G\n");
} else if (x==) {
if (g[n][m]==-) printf("D\n");
else if (g[n][m]==) printf("B\n");
else printf("G\n");
} else {
n--;m--; //同理
if (n>m) swap(n,m);
x=(int)(n*(sqrt()-)/);
if (n==(int)(x*(+sqrt())/)&&n+x==m) printf("G\n");
else if (n==(int)((x+)*(+sqrt())/)&&n+x+==m) printf("G\n");
else printf("B\n");
}
}
return ;
}
5754Life Winner Bo的更多相关文章
- HDU 5754Life Winner Bo
Life Winner Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 5754 Life Winner Bo 组合博弈
Life Winner Bo Problem Description Bo is a "Life Winner".He likes playing chessboard gam ...
- HDU 5754 Life Winner Bo (博弈)
Life Winner Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life W ...
- hdu_5754_Life Winner Bo(博弈)
题目链接:hdu_5754_Life Winner Bo 题意: 一个棋盘,有国王,车,马,皇后四种棋子,bo先手,都最优策略,问你赢的人,如果双方都不能赢就输出D 题解: 全部都可以直接推公式, 这 ...
- hdu-5754 Life Winner Bo(博弈)
题目链接: Life Winner Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- HDU5754 Life Winner Bo(博弈)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life Winner" ...
- Life Winner Bo HDU - 5754
Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G. The size of ...
- HDU 5754 Life Winner Bo (各种博弈) 2016杭电多校联合第三场
题目:传送门 题意:一个国际象棋棋盘,有四种棋子,从(n,m)走到(1,1),走到(1,1)的人赢,先手赢输出B,后手赢输出G,平局输出D. 题解:先把从(n,m)走到(1,1)看做是从(1,1)走到 ...
- HDU 5754 Life Winner Bo (找规律and博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5754 给你四种棋子,棋子一开始在(1,1)点,两个人B和G轮流按每种棋子的规则挪动棋子,棋子只能往右下 ...
随机推荐
- Paint与Canvas的简单用法
参考:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=278237 自定义View 重写onDraw方法 package com. ...
- Slithice 分布式架构设计
项目原因: 参与过各种 分布式项目,有 Socket,Remoting,WCF,当然还有最常用的可以跨平台的 WebService. 分布式编码的时间浪费: 但是,无一例外的,开发分布式程序的开发遵循 ...
- 筛法求质——poj2262&2909
这两道题都是哥赫巴德猜想的内容.基本的技术点都是在一个很大的数字范围里面求质数.直接判断两个数是不是质数,这种方法虽然可行但是还是很慢的.所以这两题我们使用打表! 而建立质数表的方法就是筛法求质,速度 ...
- MongoDB学习之--安全和认证
MongoDB学习之--安全和认证 本文主要介绍两部分内容,Mongodb的安全检查配置以及安全认证操作: 虽然确保系统安全是系统管理员的重要工作,但是作为程序员了解其机制也是大有好处的,毕竟不是每个 ...
- Attempted to lock an already-locked dir异常解决方法
有时候因网络太慢或中断 就会出现这种锁定状态 Attempted to lock an already-locked dir svn: Working copy 'D:\MyEclipse\mypro ...
- springMVC3学习(十二)--文件上传优化CommonsMultipartResolver
基于上一篇文件上传发现效率很慢,我们应该对它进行优化 使用springMVC对文件上传的解析器 来处理文件上传的时候需要在spring的applicationContext里面加上springMVC ...
- No CurrentSessionContext configured 异常解决
Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext conf ...
- 改善C#公共程序类库质量的10种方法和工具
最近重构一套代码,运用以下几种方法,供参考. 1 公共方法尽可能的使用缓存 public static List<string> GetRegisteredCompany() { Str ...
- Using CrunchBase API
Let us have fun with CrunchBase API. What can CrunchBase API give us? They said: https://developer.c ...
- service structure flowchart [mobile to server via HTTP RESTful API]
Modern flowchart for mobile, server, and etc.. communication This has something to do with these sou ...