您的位置:首页 > Web前端

hdu5754 多校3 Life Winner Bo【博弈】

2016-07-26 19:22 435 查看
Life Winner Bo

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 68 Accepted Submission(s): 21

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

思路

四种棋子,四种博弈

1. 王 可横竖斜走一步,打表可以找出规律;

2. 车 可横竖任意步,巴什博弈;

3. 马 打表找规律, 注意游戏中不会赢时会刻意向平局移动

4. 后 威佐夫博弈

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int s[1010][1010];

void init()
{
memset(s, -1, sizeof(s));
s[0][0] = 0;

for(int i = 0; i <= 1000; i++)
for(int j = 0; j <= 1000; j++)
{
if(i-1 >= 0 && j-2>= 0 && s[i-1][j-2] == 0)
{
s[i][j] = 1;
continue;
}
if(i-2 >= 0 && j-1>= 0 && s[i-2][j-1] == 0)
{
s[i][j] = 1;
continue;
}

if(i-1 >= 0 && j-2>= 0 && s[i-1][j-2] == 1 && i-2 >= 0 && j-1>= 0 && s[i-2][j-1] == 1)
s[i][j] = 0;
}
}

int main()
{
init();
int t;
scanf("%d", &t);
while(t--)
{
int type, n, m;
scanf("%d%d%d", &type, &n, &m);
n--;
m--;
if(type  == 1)
{
if((n&1) || (m&1))
puts("B");
else
puts("G");
}
else if(type == 2)
{
if(n != m)
puts("B");
else
puts("G");
}
else if(type == 3)
{
if(s
[m] == 1)
puts("B");
else if(s
[m] == 0)
puts("G");
else
puts("D");
}
else
{
if(n > m)
swap(n, m);
int k = m - n;
int ak = k * (1 + sqrt(5))/2*(1+eps);
if(n != ak)
puts("B");
else
puts("G");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  博弈 多校