2016多校联赛3C (hdu5754) Life Winner Bo

Life Winner Bo

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 61    Accepted Submission(s): 16


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  xx  and  yy .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.

T1000,2N,M1000,1type4
 

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

思路:自己百度一下国际象棋的走法。然后画一下图就可以知道判断了。

把不同种类的棋分开判断一下。

代码加注释如下:

#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1200;
bool matc[maxn][maxn];
bool vis[maxn];
bool king(int x,int y)//国王的走法 
{
	if(x%2&&y%2)return false;
	return true;
}
bool rook(int x,int y)//车的走法 
{
	if(x==y)return false;
	return true;
}
bool queen(int x,int y)//皇后的走法 
{
	if(matc[x][y])return false;
	return true;
}
int knight(int x,int y)//马的走法 
{
	if(x==y)
	{
		if((x-1)%3==0)return 0;
	}
	else if(x+1==y+2)
	{
		if((x+1-1)%3==0)return 1;
	}
	else if(y+1==x+2)
	{
		if((y+1-1)%3==0)return 1;
	}
	return -1;
}
void makematc()//威佐夫博弈打表  皇后的走法刚好就可以套上威佐夫博弈
{
	int x=1,y=1;
	for(int i=1;;i++)
	{
		int add=1;
		while(vis[x+add]||vis[y+1+add])add++;
		x+=add,y+=add+1;
		if(!(x<=1100&&y<=1100))break;
		vis[x]=vis[y]=true;
		matc[x][y]=true;
		matc[y][x]=true;
	}
} 
int main()
{
	int x,y,t,T;
	cin>>T;
	while(T--)
	{
		cin>>t>>x>>y;
		bool flag=false;
		if(t==1){if(king(x,y))flag=true;}
		else if(t==2){if(rook(x,y))flag=true;}
		else if(t==3)
		{
			int pos=knight(x,y);
			if(pos==1)flag=true;
			else if(pos==-1){cout<<"D"<<endl;continue;}
		}
		else if(queen(x,y))flag=true;
		if(flag)cout<<"B"<<endl;
		else cout<<"G"<<endl;
	}	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值