HDU 5754 Life Winner Bo 博弈

3 篇文章 0 订阅

这次多校感觉全是数学题啊……然而最不会的就是数学题……


Life Winner Bo

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


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
 

Source
 

题意:给定一个n*m的棋盘,再给定四种棋子中的一种,放在(1,1)点。bo和他的女朋友轮流走,每次不能往左上方向走,谁先到达(n,m)点谁赢,现让你输出谁是赢家,若无法得出赢家则输出D(平局)


思路:比赛的时候想的是打表,一神写了一发T了……

之后找规律,发现king的表是一个很有规则的01相间的表,当n与m都是奇数时后手必赢。

车的话,通过打表发现,当n==m的时候,后手比赢,因为无论怎么走,后手都能使棋子回到对角线上。

马,这个是最麻烦的,也是通过打表找规律,要注意打表的时候,在某些情况下,先手可能会走到死角使局势变为平局。

皇后,这个其实就是一个裸的威佐夫博弈,把x与y看成两堆石子,一次只能从x或y中取任意数,或者走斜线在x与y中取相同的某数,套公式就行了(比赛前才在伟佳巨的博客中看到这个模型,比赛快结束的时候才发现……还是太水了……)


代码:

#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{
	int i,j,k,m,n;
	int t;
	scanf("%d",&t);
	while(t--)
	{   int c;
		scanf("%d%d%d",&c,&n,&m);
	    if(c==1)
	    {
	    	if(n%2==1 && m%2==1)printf("G\n");
	    	 else printf("B\n");
		}
		if(c==2)
		{
			if(n==m)printf("G\n");
			  else printf("B\n");
		}
		if(c==3)
		{
			if(n==m && (n-1)%3==0 &&(n>=4))printf("G\n");
			 else
			  {
			  	if(n<m)swap(n,m);
			  	if(n%3==0 && (m-2)%3==0 && n-m==1)printf("B\n");
			  	 else
			  	  printf("D\n");
			  }
		}
		if(c==4)
		{
			if(n<m)swap(n,m);
			n=n-1;
			m=m-1;
			double ak=(double)(1.0+sqrt(5.0))/(double)2.0;
			int k=n-m;
			if(int(ak*k)==m)printf("G\n");
			 else printf("B\n");
		}
	
	}
	
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值