|
Life Winner BoTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2139 Accepted Submission(s): 779
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
Sample Output
Author
绍兴一中
Source
题目大意: 有一个 先介绍一下四种棋子的移动规则:
题目要求不能移动且没有到右下角时为平手,那么只有knight可能出现平手,即走到边界时不能再移动. * 对于第一种情况:先分析九个格子的情况,右下角为终点,然后依次往外找,能到必败态的一定是必胜态,只能到必胜态的一定是必败态。然后 可以发现当n%2 == 0 || m%2 == 0时,先手必胜,否则,先手必败。 * 对于第二种情况:当n==m(正方形)时先手必败,因为无论先手怎么走后手都能走到对角线上,同理当n!=m时先手直接走到对角线上,和前面 一样,此时先手必胜。 * 对于第三种情况:只有这种情况会走不到终点而出现平局,先考虑一定能走到终点的情况,往下走相当于往右走一个再往下走两个,往右走相当 与往右走两格再往下走一格。假设往右和往下走的步数分别为x, y则必有:
{2x+y=m−12y+x=n−1
解得:
:
x=2m−n−13,y=2n−m−13
,可得总步数为
m+n−23
,故当m+n-2是3的倍数时一定能走到终点,再考虑当x==y时,先手必败,当
abs(x-y)==1时先手必胜,当abs(x-y)>1时,总有一方可以走到边界制造平局。 * 对于第四种情况,将往右和往下分堆,则斜着走相当于从两堆中取石子,往右或者往下走分别代表从一堆中取和从另一堆中取,即为威左夫博弈 代码如下:
(m+n−2) 的时候,x |
HDU_5754 Life Winner Bo
最新推荐文章于 2017-04-12 10:08:24 发布