日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > > 充電吧
[導讀]題面: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ā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

納祥科技推出太陽能+Type-C雙充電自行車前燈方案,方案核心模塊包含太陽能板、單片機、三極管、3顆LED燈珠與1200mAh電池,通過低功耗單片機與三極管驅動,支持強光/弱光/爆閃3種模式,高流明遠射程,適配多種車型

關鍵字: 方案開發(fā) 電子方案 自行車前燈方案 納祥科技

慕尼黑2025年9月11日 /美通社/ -- 當?shù)貢r間9月9日,賽力斯動力在德國慕尼黑國際車展期間舉辦技術發(fā)布與交流會,正式在海外市場推出全新一代賽力斯超級增程、高效發(fā)動機和新一代分布式電驅動系統(tǒng),同時與來自全球的汽車產(chǎn)...

關鍵字: 慕尼黑 分布式 發(fā)動機 新能源汽車

慕尼黑2025年9月11日 /美通社/ -- 高端智能電動汽車品牌問界(AITO)在2025年德國國際汽車及智慧出行博覽會(IAA MOBILITY)上,正式發(fā)布了其最新全球產(chǎn)品陣容——專為中東市場深度本地化打造的AIT...

關鍵字: AI 智能駕駛 測試 生態(tài)系統(tǒng)

舍弗勒首次為中國頭部車企大規(guī)模生產(chǎn)高壓逆變磚 天津工廠一年內(nèi)完成量產(chǎn)準備,逆變器模塊性能參數(shù)顯著提升 與合作伙伴羅姆半導體共研尖端碳化硅技術,效率更高、性能更優(yōu) 模塊化可擴展設計使逆變磚易于集成,可廣泛...

關鍵字: 逆變 高壓 逆變器 集成

舍弗勒以"專注驅動技術的科技公司"為主題亮相IAA MOBILITY 2025(B3館B40展臺) 合并緯湃科技后首次亮相IAA MOBILITY,展示拓展后的汽車產(chǎn)品組合 憑借在軟件、...

關鍵字: 電氣 軟件 驅動技術 BSP

拉斯維加斯2025年9月11日 /美通社/ -- 在9月8日至11日舉辦的RE+ 2025展會上,全球綜合儲能解決方案供應商德賽電池(Desay Battery)全面展示了其創(chuàng)新成果,并宣布與深圳市華寶新能源股份有限公司...

關鍵字: 電池 電芯 人工智能 鋰電

香港2025年 9月12日 /美通社/ -- 全球領先的互聯(lián)網(wǎng)社區(qū)創(chuàng)建者 - 網(wǎng)龍網(wǎng)絡控股有限公司 ("網(wǎng)龍"或"本公司",香港交易所股票代碼:777)欣然宣布,其子公司My...

關鍵字: AI 遠程控制 控制技術 BSP

慕尼黑2025年9月12日 /美通社/ -- 慕尼黑當?shù)貢r間9月10日,在2025德國國際汽車及智慧出行博覽會(IAA MOBILITY)上,國際獨立第三方檢測、檢驗和認證機...

關鍵字: 測試 慕尼黑 模型 HUBER

上海2025年9月12日 /美通社/ -- 近日,國際獨立第三方檢測、檢驗和認證機構德國萊茵TÜV大中華區(qū)(簡稱"TÜV萊茵")為上海...

關鍵字: 測試 信息安全 安全管理 開關

廣州2025年9月12日 /美通社/ -- 9月11日,由國際獨立第三方檢測、檢驗和認證機構德國萊茵TÜV大中華區(qū)(簡稱"TÜV萊茵"...

關鍵字: 數(shù)字化 供應鏈 控制 電子
關閉