博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU5754 Life Winner Bo(博弈)
阅读量:5058 次
发布时间:2019-06-12

本文共 1907 字,大约阅读时间需要 6 分钟。

题目

Source

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

 

分析

题目大概说给一个n*m的棋盘,棋子一开始在(1,1),两人交替移动棋子,移动的时候只能向右下方向走,走到(n,m)者赢,如果不能移动那就平局。问当棋子是king、rook、knight和queen时先手是必胜还是败,或者平局。

 

  • king:上下左右斜都能走,但只能走一格
  • rook:能走上下左右,格子不限
  • knight:只能走日字型
  • queen:上下左右斜都能走且无限制

 

这题其实很简单。原理就是:当前处于终点局面的人必败,因为他没办法走棋,这是必败态;如果一个局面能转移到必败态的局面,那么这个局面是必胜的;如果一个局面只能转移到必胜局面那这个局面是必败态。

根据这个原理去记忆化搜索。另外,考虑一下平局的情况,如果能平局就不要输即可,而平局只有棋子是knight时才可能发生。

 

比赛时,king是直接记忆化搜索预处理出来的,rook则是直接记忆化搜索找到规律的,knight也是直接记忆化搜索预处理出来的,queen直接把1000多个必败态打表出来的。。

 

值得一提的是官方题解中queen可以通过前缀和使得记忆化搜索中的转移达到O(1) ,这样就不怕超时了,而事实上queen的走法其实是一个经典的威佐夫博奕

 

代码

代码就不贴了= =。。

转载于:https://www.cnblogs.com/WABoss/p/5709187.html

你可能感兴趣的文章
ES6内置方法find 和 filter的区别在哪
查看>>
Android入门之文件系统操作(二)文件操作相关指令
查看>>
Android实现 ScrollView + ListView无滚动条滚动
查看>>
java学习笔记之String类
查看>>
UVA 11082 Matrix Decompressing 矩阵解压(最大流,经典)
查看>>
jdk从1.8降到jdk1.7失败
查看>>
一些关于IO流的问题
查看>>
mongo备份操作
查看>>
8 -- 深入使用Spring -- 3...1 Resource实现类InputStreamResource、ByteArrayResource
查看>>
硬件笔记之Thinkpad T470P更换2K屏幕
查看>>
一个关于vue+mysql+express的全栈项目(六)------ 聊天模型的设计
查看>>
【知识库】-数据库_MySQL 的七种 join
查看>>
.net 写文件上传下载webservice
查看>>
noSQL数据库相关软件介绍(大数据存储时候,必须使用)
查看>>
iOS开发——缩放图片
查看>>
HTTP之URL的快捷方式
查看>>
满世界都是图论
查看>>
配置链路聚合中极小错误——失之毫厘谬以千里
查看>>
代码整洁
查看>>
蓝桥杯-分小组-java
查看>>