www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當前位置:首頁 > 芯聞號 > 充電吧
[導讀]題面: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值的計算是,其后續(xù)狀態(tài)(即操作一步之后達到的狀態(tài))的SG值集合中未出現(xiàn)過的最小自然數(shù)。棋盤的狀態(tài)可以用二進制位表示,1代表有棋子,0代表無棋子。枚舉每個狀態(tài)的后繼,計算該狀態(tài)的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];
//尋找后續(xù)狀態(tài)
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--;
		???//逐次替換連續(xù)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));
	//初始化必輸態(tài)
	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++)
????????????{
				//構建進制表示狀態(tài)
				scanf("%d",&tmp);
				status+=(1<<(20-tmp));
			}
			//異或得出結果
			res^=dp[status];
		}
		if(res)
			printf("YESn");
		else
			printf("NOn");
	}
	return?0;
}



本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或將催生出更大的獨角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉型技術解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術公司SODA.Auto推出其旗艦產品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關鍵字: 汽車 人工智能 智能驅動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務中斷的風險,如企業(yè)系統(tǒng)復雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務連續(xù)性,提升韌性,成...

關鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網易近期正在縮減他們對日本游戲市場的投資。

關鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產業(yè)博覽會開幕式在貴陽舉行,華為董事、質量流程IT總裁陶景文發(fā)表了演講。

關鍵字: 華為 12nm EDA 半導體

8月28日消息,在2024中國國際大數(shù)據(jù)產業(yè)博覽會上,華為常務董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權最終是由生態(tài)的繁榮決定的。

關鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應對環(huán)境變化,經營業(yè)績穩(wěn)中有升 落實提質增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務引領增長 以科技創(chuàng)新為引領,提升企業(yè)核心競爭力 堅持高質量發(fā)展策略,塑強核心競爭優(yōu)勢...

關鍵字: 通信 BSP 電信運營商 數(shù)字經濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術學會聯(lián)合牽頭組建的NVI技術創(chuàng)新聯(lián)盟在BIRTV2024超高清全產業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術創(chuàng)新聯(lián)...

關鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關鍵字: BSP 信息技術
關閉
關閉