当前位置:首页 > 芯闻号 > 充电吧
[导读]题目链接:HDU 5754 题面: Life Winner Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/13

题目链接:HDU 5754


题面:

Life Winner Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 827    Accepted Submission(s): 309


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

 

Source 2016 Multi-University Training Contest 3


题意:

     给定N*M的棋盘,一共4颗棋子,每次一种1颗棋子,从左上角出发,到右下角的人获胜。


解题:

    1.王的走法是向下向右1格,或同时向下向右1格,即(x+1,y)/(x,y+1)/)(x+1,y+1)三种走法,递推推一下即可。一个节点的后继为必败态,那么它为必胜态,如果一个节点的后继全都是必胜态,那么它就是必败态,按剩余步数,从小到大递推一下即可。

     2.车的走法是横向或竖向任意格,那么在对角线上必输,因为先手走什么策略,后手模仿即可,反之n!=m,先手只要使对方到对角线上即必胜。

     3.马的走法和中国象棋是一样的,日字形,马比较特殊的是,会出现平局的情况,即谁都不能到达(n,m),马的递推是,如果后继中有必败态,那么当前节点是必胜态,如果后继中都是必胜态,那么当前节点是必败态,如果后继中有平局,那么当前节点即为平局。(以上推导严格有序,即在排除了前一种情况的前提下成立)。

    4.皇后的走法和王类似,不过王后是走任意步,或者沿斜线任意步。这其实可以看成,两堆石子,要么从一堆取任意个,要么从两堆同时取相同任意个。这就是威佐夫博弈,可见这篇博客。

     这题综合考察了几种博弈,还是很不错的,没有接触过博弈的人,可以学到很多。


代码:

#include 
#include 
#include 
#include 
#include 
#include 
#define LL long long
using namespace std;
bool king[1005][1005];
int horse[1005][1005];
bool vis[1005][1005];
int main()
{
	int t,type,n,m,s1,s2;
	memset(king,0,sizeof(king));
	king[0][0]=0;
	for(int i=0;i<=1000;i++)
	{
		for(int j=0;j<=1000;j++)
		{
			if(king[i][j]==0)
			{
				if(i+1<=1000)
				    king[i+1][j]=1;
				if(j+1<=1000)
					king[i][j+1]=1;
                if(i+1<=1000&&j+1<=1000)
					king[i+1][j+1]=1;
			}
		}
	}
    memset(horse,-1,sizeof(horse));
	horse[0][0]=0;
	for(int i=0;i<=1000;i++)
	{
		for(int j=0;j<=1000;j++)
		{
			s1=-2;s2=-2;
		   if(i-1>=0&&j-2>=0)
              s1=horse[i-1][j-2];
		   if(i-2>=0&&j-1>=0)
			  s2=horse[i-2][j-1];
           if(s1!=-2&&s2!=-2)
		   {
			   if(s1==0||s2==0)
				   horse[i][j]=1;
			   else if(s1==-1||s2==-1)
				   horse[i][j]=-1;
			   else
				   horse[i][j]=0;
		   }
		   if(s1!=-2||s2!=-2)
		   {
			   if(s1==0||s2==0)
				   horse[i][j]=1;
			   else if(s1==-1||s2==-1)
				   horse[i][j]=-1;
			   else
				   horse[i][j]=0;
		   }
		  
		}
	}
	scanf("%d",&t);
    while(t--)
	{
		int flag;
		scanf("%d%d%d",&type,&n,&m);
		if(type==1)
		{
			if(king[n-1][m-1]==1)
				flag=1;
			else
				flag=0;
		}
		else if(type==2)
		{
			if(n==m)
				flag=0;
			else
				flag=1;
		}
		else if(type==3)
		{
			n--;
			m--;
			if(horse[n][m]==-1)
				flag=2;
			else if(horse[n][m])
				flag=1;
			else
				flag=0;
		}
		else
		{
			int dif,tmp;
			n--;
			m--;
			if(n>m)
				swap(n,m);
		    dif=m-n;
			tmp=dif*(1.0+sqrt(5.0))/2;
			if(n==tmp)
				flag=0;
			else
				flag=1;
		}
		if(flag==2)
			printf("Dn");
		else if(flag==1)
			printf("Bn");
		else
			printf("Gn");
	}
	return 0;
}



本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

5 月 13 日消息,从“上海临港”微信公众号获悉,特斯拉上海储能超级工厂建设项目已完成施工许可证核发。这是特斯拉在美国本土以外的首个储能超级工厂项目,工厂计划于今年 5 月开工,明年一季度实现量产。

关键字: 特斯拉 储能

据消息源 jasonwill101 透露,高通公司目前正在重新设计骁龙 8 Gen 4 处理器,新的目标频率为 4.26GHz,这一变化主要是为了应对苹果 M4 / A18 / Pro 处理器。

关键字: 高通 骁龙 8 Gen 4 芯片

最新消息,今天凌晨 OpenAI 在春季更新直播官宣发布最新旗舰生成式 AI 模型 GPT-4o,GPT-4o 将 ChatGPT 变成一名带有文本、「视觉」与语音互动的实时语音助手。OpenAI 表示升级版的 Chat...

关键字: OpenAI 生成式 AI大模型 GPT-4o

三星电子最近进行了重大的组织重组,以增强其在下一代机器人业务方面的能力,并将其视为关键增长领域。作为重组的一部分,该公司解散了负责开发三星首款可穿戴机器人“Bot Fit”的机器人业务团队。

关键字: 三星电子 解散 Bot Fit 机器人

NAS这些年可吸引了不少数码发烧友的注意,但也渐渐在家庭用户中风靡。究其原因,大概还是因为太多人因为现在数据过于庞大,而一个NAS基本上就能解决一个家庭的数据存储难题。在这一背景下,铁威马F4-424 Pro凭借其出色的...

关键字: NAS 数据存储 处理器

央视《今日说法》栏目近期报道了一名90后程序员通过开发非法视频搬运软件在不到一年的时间里获利超700万,最终获刑的案例。

关键字: 程序员 软件

业内消息,近日美国麦肯锡公司的一份报告强调了芯片行业的劳动力挑战,在美国寻求吸引更多技术工人从事半导体制造之际,许多现有员工正在重新考虑是否要留下来。

关键字: 芯片

业内消息,近日美国商务部工业与安全局(BIS)根据出口管理条例(EAR)将中国电子科技集团旗下多个研究所、中电科芯片技术(集团)有限公司、中国科学技术大学,以及北京量子信息科学研究院、本源量子等 37 个中国实体添加到实...

关键字: 实体清单

5 月 11 日消息,鲲鹏昇腾开发者大会昨日在北京中关村国际创新中心举办,主题为“心怀挚爱,共绽光芒”,会上推出了原生使能计划、启动鲲鹏昇腾科教创新卓越中心、鲲鹏昇腾原生创新汇等。

关键字: 华为 鲲鹏昇腾

近日路透社援引知情人士的消息称,美国商务部正考虑推动一项新的监管措施,将限制 AI 模型的出口,初步计划对 ChatGPT 等大模型采取行动。

关键字: AI
关闭
关闭