Life Winner Bo

Problem Description
 
Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G.

The size of the chessboard is N×M.The top left corner is numbered(1,1) and the lower right corner is numberd (N,M).

For each game,Bo and G take turns moving a chesspiece(Bo first).At first,the chesspiece is located at (1,1).And the winner is the person who first moves the chesspiece to (N,M).At one point,if the chess can't be moved and it isn't located at (N,M),they end in a draw.

In general,the chesspiece can only be moved right or down.Formally,suppose it is located at (x,y),it can be moved to the next point (x′,y′) only if x′≥x and y′≥y.Also it can't be moved to the outside of chessboard.

Besides,There are four kinds of chess(They have movement rules respectively).

1.king.

2.rook(castle).

3.knight.

4.queen.

(The movement rule is as same as the chess.)

For each type of chess,you should find out that who will win the game if they both play in an optimal strategy.

Print the winner's name("B" or "G") or "D" if nobody wins the game.

 
Input
 
In the first line,there is a number T as a case number.

In the next T lines,there are three numbers type,N and M.

"type" means the kind of the chess.

T≤1000,2≤N,M≤1000,1≤type≤4

 
Output
 
For each question,print the answer.
 
Sample Input
 
4
1 5 5
2 5 5
3 5 5
4 5 5
 
Sample Output
 
G
G
D
B
 

题意:

  4种棋。

  棋子首先在(1,1),你要移动到(n,m);

  谁先移动到终点谁就赢了,注意骑士可能走向平局

题解:

  首先国王可以预处理答案

  皇后是威佐夫博弈

  车是个典型的nim博弈

  骑士呢,你注意到有个平局,就是说,如果当前走下一个状态的时候,面临了必败和平局的情况,你是要走平局的,这个点注意一下就能AC了

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = 3e3+, M = 2e5+, mod = 1e9+, inf = 2e9;
int h[],gw[N][N],qs[N][N];
void init() {
gw[][] = ;
for(int i = ; i <= ; ++i) {
for(int j = ; j <= ; ++j) {
memset(h,,sizeof(h));
if(i>=)h[gw[i-][j]] = ;
if(j>=)h[gw[i][j-]] = ;
if(i>=&&j>=) h[gw[i-][j-]] = ;
if(h[]) gw[i][j]=;
else gw[i][j] = ;
}
}
memset(qs,-,sizeof(qs));
qs[][] = ;int cnt = ;
for(int i = ; i <= ; ++i) {
for(int j = ; j <= ; ++j) {
int ok = ;
memset(h,,sizeof(h));
if(i>=&&j>=&&qs[i-][j-]!=-&&qs[i-][j-]<=)h[qs[i-][j-]] = ,ok = ;
if(j>=&&i>=&&qs[i-][j-]!=-&&qs[i-][j-]<=)h[qs[i-][j-]] = ,ok++;
if(i == && j == ) continue;
if(ok) {
if(h[]) qs[i][j] = ;
else if(!h[] && ok < ) qs[i][j] = -;
else qs[i][j] = ;
}
else qs[i][j] = -; }
}
// cout<<cnt<<endl;
// cout<<qs[1][2]<<endl;
}
int main() {
int T;init();
scanf("%d",&T);
while(T--) {
int type,n,m;
scanf("%d%d%d",&type,&n,&m);
n--,m--;
if(type == ) {//国王
if(gw[n][m])printf("B\n");
else printf("G\n");
} else if(type == ) {//车
if((n ^ m) != )printf("B\n");
else printf("G\n");
} else if(type == ) {//马
if(qs[n][m]==-) printf("D\n");
else if(qs[n][m]) printf("B\n");
else printf("G\n");
} else {//皇后
if(n > m) swap(n,m);
double k = (sqrt()-1.0)/2.0;
int j = n * k;
if(n != (int) (j*(+k))) j++;
if(n + j == m) printf("G\n");
else printf("B\n");
}
}
return ;
}

HDU 5754 Life Winner Bo 组合博弈的更多相关文章

  1. HDU 5754 Life Winner Bo (博弈)

    Life Winner Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life W ...

  2. HDU 5754 Life Winner Bo (各种博弈) 2016杭电多校联合第三场

    题目:传送门 题意:一个国际象棋棋盘,有四种棋子,从(n,m)走到(1,1),走到(1,1)的人赢,先手赢输出B,后手赢输出G,平局输出D. 题解:先把从(n,m)走到(1,1)看做是从(1,1)走到 ...

  3. HDU 5754 Life Winner Bo (找规律and博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5754 给你四种棋子,棋子一开始在(1,1)点,两个人B和G轮流按每种棋子的规则挪动棋子,棋子只能往右下 ...

  4. HDU 5754 Life Winner Bo(各类博弈大杂合)

    http://acm.hdu.edu.cn/showproblem.php?pid=5754 题意: 给一个国际象棋的棋盘,起点为(1,1),终点为(n,m),现在每个棋子只能往右下方走,并且有4种不 ...

  5. 【博弈论】HDU 5754 Life Winner Bo

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 题目大意: 4种棋子,象棋中的 1王,2车,3马,4后,选其一,B和G轮流走,不能往左上走,一 ...

  6. HDU 5754 Life Winner Bo

    四种棋子实质上都是一样的思路: 如果某位置的棋子,它下一步可以走到的位置中 能找到有后手胜的位置,那么该位置先手必胜. 如果某位置的棋子,它下一步可以走到的位置中 全是先手胜,那么该位置后手必胜. 其 ...

  7. hdu 5754 Life Winner Bo 博弈论

    对于king:我是套了一个表. 如果起点是P的话,则是后手赢,否则前手赢. 车:也是画图推出来的. 马:也是推出来的,情况如图咯. 对于后:比赛时竟然推错了.QAQ最后看了题解:是个威佐夫博奕.(2, ...

  8. HDU5754 Life Winner Bo(博弈)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5754 Description Bo is a "Life Winner" ...

  9. hdu-5754 Life Winner Bo(博弈)

    题目链接: Life Winner Bo Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/ ...

随机推荐

  1. RabbitMQ学习系列(四): 几种Exchange 模式

    上一篇,讲了RabbitMQ的具体用法,可以看看这篇文章:RabbitMQ学习系列(三): C# 如何使用 RabbitMQ.今天说些理论的东西,Exchange 的几种模式. AMQP协议中的核心思 ...

  2. 回顾Spirng ioc 控制反转

    Spring的IoC(控制反转) .DI(依赖注入)这两个概念,对于初学Spring的人来说,总觉得IoC .DI这两个概念是模糊不清的,是很难理解的.结合网上对Spring Ioc的理解,回顾一下自 ...

  3. python版本随意切换之python2.7+django1.8.7+uwsgi+nginx源码包部署。

    资源准备: wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz wget https://www.djangoproject ...

  4. select、poll、epoll之间的区别总结[整理]

    select,poll,epoll都是IO多路复用的机制.I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪(一般是读就绪或者写就绪),能够通知程序进行相应的读写操作.但select ...

  5. 如何保存gnome的linux的 会话?相当于windows下的休眠?

    在关机前, 你进行的所有操作, 的集合, 就叫做你跟 linux系统 机器间的 一次 会话, 一个session. linux 可以 在关机时保存 这些session, 保存这些打开的窗口 和程序. ...

  6. Java优先队列

    按照Java api的说法: java.util.PriorityQueue.PriorityQueue() Creates a PriorityQueue with the default init ...

  7. 字符串 HDU 1039

    规则: 1.必须至少包含一个元音字母.a e i o u 2.不能包含三个连续元音或者连续辅音字母. 3.不能包含两个连续字母,除了'ee'和'oo'. PS:字母个数(1<= N <=2 ...

  8. 【IOS】模仿"抽屉新热榜"动态启动页YFSplashScreen

    IOS最好要设置系统默认启动页面,不然进入应用就会突然闪现黑色画面 下图是我们要实现的效果: 总体思路:设置一个系统默认启动页面,在进入didFinishLaunchingWithOptions时, ...

  9. excel 2010 学习笔记一 Vlookup 函数的使用

    有这么一句话说的好:在商用场合里,能证明你会基本的EXCEL操作技巧的两个检查标准就是会不会用VLOOKUP函数以及数据透视表功能,那么今天就来总结一下VLOOKUP的一些简单实用的功能. 1.VLO ...

  10. Typescript基础类型

    1.布尔值__boolean 2.数字__number----除了支持十进制和十六进制字面量,Typescript还支持ECMAScript 2015中引入的二进制和八进制字面量. 3.字符串__st ...