HDU 5754 Life Winner Do (多种博弈结合)

Life Winner Bo

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


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

http://acm.hdu.edu.cn/showproblem.php?pid=5754

题意就是给一个端点,有四种棋子,看谁先走到谁赢,不然就是平局,每种棋子均有自己的走法,但要求只能向右向下走

可以分别看作四种不同的博弈,和我一开始想着暴力打表找规律完全不同,怎么做都得有道理的啊

1 king    向周围八个方向移动一步
2 castle   移动到同一行或者同一列的任意位置
3 knight  向2*3的矩阵的另一个角移动
4 queen 移动到同意行列斜线的任意位置


1.  两堆石头,n,m,一次从其中一堆取出一个或者从两堆中各取出一个,谁先到(0,0)谁就赢

    (0,0)对应的是(偶数,偶数)的状态

    要赢就是自己下一步的状态是(偶数,偶数)

    而(偶,偶)经过转换一步只能到(偶,奇)  (奇,偶) (奇,奇)

    这三个状态一步均可到(偶,偶)   所以处于(偶,偶)的是先手必输的

    在这里,要走n-1 和 m-1步,就是说n-1 m-1都是偶数(也可以判断n m都是奇数),先手必输,否则先手必赢

2.Nimm博弈模型,从两堆中取,个数不限,取到最后一个的赢

    异或之后结果为0的话后手必赢,否则先手必赢


3.  从一堆取一个,从另一堆取两个 ,或者相反 ,这个时候明显(3*k,3*k)是一种先手必输的状态,

先手要想赢就得使对手处于这个状态,如果两堆石头的个数为(3*k+1 ,  3*k+2)或者(3*k+2, 3*k+1)

那么先手必胜,否则为平局


4.威佐夫博弈模型

    

 威佐夫博弈(Wythoff Game):

有两堆各若干的物品,两人轮流从其中一堆取至少一件物品,至多不限,或从两堆中同时取相同件物品,规定最后取完者胜利。

直接说结论了,若两堆物品的初始值为(x,y),且x<y,则另z=y-x;

记w=(int)[((sqrt(5)+1)/2)*z  ];

若w=x,则先手必败,否则先手必胜。

讨论完就很容易写了



#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int type,n,m,terms;
	scanf("%d",&terms);
	while(terms--)
	{
		scanf("%d%d%d",&type,&n,&m);
		n--;
		m--;
		if(type == 1)
		{
			if(n%2==0 && m%2==0)
				printf("G\n");
			else
				printf("B\n");
		}
		else if(type == 2)
		{
			int temp=0;
			temp^=n;
			temp^=m;
			if(!temp)
				printf("G\n");
			else
				printf("B\n");
		}
		else if(type == 3)
		{
			if(n==m && m%3==0)
				printf("G\n");
			else if(abs(m-n)==1 && (min(m,n)-1)%3==0)
				printf("B\n");
			else
				printf("D\n");
		}
		else if(type == 4)
		{
			if(n>m)
				swap(n,m);
			int temp=floor( (m-n) * (sqrt(5) + 1)/2.0 );
			if(temp == n)
				printf("G\n");
			else
				printf("B\n");
		}
	}
	return 0;	
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值