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

當前位置:首頁 > 芯聞號 > 充電吧
[導讀]題面:A Simple Nim Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/65536 K (Java/Others)T

題面:


A Simple Nim Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 300????Accepted Submission(s): 211


Problem Description Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed).To make the game more interesting,players can separate one heap into three smaller heaps(no empty heaps)instead of the picking operation.Please find out which player will win the game if each of them never make mistakes. ?
Input Intput contains multiple test cases. The first line is an integer 1≤T≤100, the number of test cases. Each case begins with an integer n, indicating the number of the heaps, the next line contains N integers s[0],s[1],....,s[n?1], representing heaps with s[0],s[1],...,s[n?1] objects respectively.(1≤n≤106,1≤s[i]≤109) ?
Output For each test case,output a line whick contains either"First player wins."or"Second player wins". ?
Sample Input


2 2 4 4 3 1 2 4 ?
Sample Output


Second player wins. First player wins. ?
Author UESTC ?
Source 2016 Multi-University Training Contest 6 ?
題意:
??? 取石子游戲,有兩種操作方式,一、在一堆中取任意顆石子,(大于0)。二、將一堆分成三堆,每堆數量大于0。取到最后一塊石子的人獲得勝利。

解題:
??? 先小數據打表求sg值,可以發(fā)現sg值的規(guī)律。當i%8==7時,其sg值為i+1,當i%8==0時,其sg值為i-1(sg[0]=0)。一個狀態(tài)的sg值,是其后繼狀態(tài)sg值中未出現過最小整數,三堆的sg值是三堆石子數量sg值的異或。根據sg值的規(guī)律,可以求解問題,官方題解說是用數學歸納法證明。

代碼:

#include#include#include#define?LL?long?long
#define?mod?1000000007
#define?sz?100005
using?namespace?std;
int?sg[sz];
bool?vis[sz];
int?main()
{
	//打表程序
	/*int?tmp;
????sg[0]=0;
	for(int?i=1;i<=50;i++)
	{
		memset(vis,0,sizeof(vis));
		for(int?j=0;j<i;j++)
			vis[sg[j]]=1;
		for(int?k=1;k<i;k++)
		{
			for(int?m=1;m0)
????????????????{
					tmp=sg[k]^sg[m]^sg[u];
					vis[tmp]=1;
				}
				else
					break;
			}
		}
		for(int?x=0;;x++)
			if(!vis[x])
			{
				sg[i]=x;
				printf("sg[%d]:?%dn",i,x);
				break;
			}
	}*/
	int?t,n,tmp,s;
	scanf("%d",&t);
????while(t--)
	{
		s=0;
		scanf("%d",&n);
????????while(n--)
		{
			scanf("%d",&tmp);
			if(tmp%8==7)
				s^=(tmp+1);
			else?if(tmp%8==0)
				s^=(tmp-1);
			else
				s^=tmp;
		}
		if(s)
			printf("First?player?wins.n");
		else
			printf("Second?player?wins.n");
	}
	return?0;
}





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