当前位置:首页 > 芯闻号 > 充电吧
[导读]题面:Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su

题面:


Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 450    Accepted Submission(s): 165


Problem Description Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the moved chess, move the chess to its right adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. Two chesses can’t be placed at one block and no chess can be placed out of the chessboard. When someone can’t move any chess during his/her turn, he/she will lose the game. Alice always take the first turn. Both Alice and Bob will play the game with the best strategy. Alice wants to know if she can win the game.  
Input Multiple test cases.

The first line contains an integer T(T≤100), indicates the number of test cases.

For each test case, the first line contains a single integer n(n≤1000), the number of lines of chessboard.

Then n lines, the first integer of ith line is m(m≤20), indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1≤pj≤20) followed, the position of each chess.
 
Output For each test case, output one line of “YES” if Alice can win the game, “NO” otherwise.  
Sample Input


2 1 2 19 20 2 1 19 1 18  
Sample Output


NO YES  
Author HIT  
Source 2016 Multi-University Training Contest 1  


题意:

    给定一个n*20的棋盘,棋盘上有若干棋子。如果一颗棋子右侧为空,则只可以向右移动一格,若非空,则可以移到第一个空的位置,两人轮流操作,不能操作者为输,问先者是否有必胜策略。


解题:

    比较简单的博弈,通过SG值的计算即可解决问题。将游戏划分为多个子游戏,每个游戏相互独立,视为一行的棋盘,最后将每行的SG值异或即可。SG值的计算是,其后续状态(即操作一步之后达到的状态)的SG值集合中未出现过的最小自然数。棋盘的状态可以用二进制位表示,1代表有棋子,0代表无棋子。枚举每个状态的后继,计算该状态的SG值。


代码:


#include#include#include#include#include#include#include#include#include#include#include#include#define eps 1e-8
using namespace std;
int dp[1100000];
//本地测试,最大值不超过30
bool vis[30];
//寻找后续状态
int dfs(int x)
{
	//记忆化搜索
	if(dp[x]!=-1)
		return dp[x];
	int tmp;
	memset(vis,0,sizeof(vis));
	for(int i=0;i<19;i++)
	{
        if((1<x)
			break;
		//找到一个和1紧邻的0
		if(((x&(1<<i))==0)&&(x&(1<<(i+1))))
		{
		   int j=i+2;
           for(;j<20;j++)
		   {
			   if(x&(1<<j))
				   continue;
			   else
				   break;
		   }
		   j--;
		   //逐次替换连续1块中的每一块
		   for(int k=i+1;k<=j;k++)
		   {
              tmp=(x-(1<<k)+(1<<i));
			  tmp=dfs(tmp);
			  vis[tmp]=1;
		   }
		}
	}
	for(int i=0;;i++)
	{
		if(!vis[i])
	    {
			dp[x]=i;
			break;
		}
	}
	return dp[x];
}	
int main()
{
	memset(dp,-1,sizeof(dp));
	//初始化必输态
	for(int i=0;i<=20;i++)
		dp[(1<<i)-1]=0;
	for(int i=1;i<=1100000;i++)
	{
		if(dp[i]==-1)
			dp[i]=dfs(i);
	}
	int t,n,m,status,res,tmp;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		res=0;
		for(int i=0;i<n;i++)
		{
			status=0;
			scanf("%d",&m);
			for(int j=0;j<m;j++)
            {
				//构建进制表示状态
				scanf("%d",&tmp);
				status+=(1<<(20-tmp));
			}
			//异或得出结果
			res^=dp[status];
		}
		if(res)
			printf("YESn");
		else
			printf("NOn");
	}
	return 0;
}



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

近日,一则有关“砺算科技濒临破产”的消息在业内不胫而走。虽然东芯股份有意收购其40%的股权,帮助砺算科技渡过难关,但这一投资事项能否最终完成仍存在不确定性。

关键字: GPU

May 14, 2024 ---- TrendForce集邦咨询研究最新显示,OLED桌上型显示器(Monitor)2024年第一季出货总量约为20万台,年成长率121%。第二季在品牌新机陆续上市后,当季成长幅度预估将达...

关键字: OLED 显示器

业内消息,近日日本软件银行集团(SoftBank Group)旗下安谋国际科技公司(Arm)计划研发人工智能(AI)芯片,先成立一个AI芯片部门,目标是明年春季建立AI芯片原型产品,然后将量产工作交由代工厂制造,预估20...

关键字: ARM AI芯片

《芯片与科学法案》(CHIPS)为美国芯片研究、开发、制造和劳动力发展提供了527亿美元的资助。

关键字: 美国芯片法案 芯片与科学法案 芯片

援引彭博社消息,近日新当选的熊本县知事木村隆(Takashi Kimura)表示,他已准备好确保获得广泛的支持,以吸引台积电在当地建立第三家日本芯片工厂。

关键字: 日本 台积电 芯片工厂

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 数据存储 处理器
关闭
关闭