1. 程式人生 > 其它 >An Ordinary Game(博弈)

An Ordinary Game(博弈)

技術標籤:補題集博弈論

Problem Statement

There is a string ss of length 33 or greater. No two neighboring characters in ss are equal.

Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first:

  • Remove one of the characters in ss, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in ss.

The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.
Constraints

  • 3≤|s|≤1053≤|s|≤105

  • ss consists of lowercase English letters.

  • No two neighboring characters in ss are equal.

Input

The input is given from Standard Input in the following format:

ss

Output

If Takahashi will win, print First. If Aoki will win, print Second.

Sample Input 1 Copy
aba

Sample Output 1 Copy
Second

Takahashi, who goes first, cannot perform the operation, since removal of the b, which is the only character not at either ends of ss, would result in ssbecoming aa, with two as neighboring.

大意:從一個任意左右不相鄰的字串中(除去兩端)取出一個字元,要保證取出字元後該字元的左右兩個字元不相等,每人取一次,最後誰取不了,誰就輸;

思路:為了保證自己贏,每一位選手都會拆除對方的圈套,那麼他們倆一定能夠對抗到最後,這時就要看兩端字元是否一樣了;

#include<iostream>
using namespace std;
int main(){
	string a;
	cin>>a;
	int n=a.size();
	if(a[0]==a[n-1])	//兩端字元相等; 
	{
		if(n%2==0) cout<<"First";	//中間有偶數個,最後一個不能取,先取的贏; 
		else cout<<"Second";
	}
	else				//兩端字元不等; 
	{
		if(n%2==0) cout<<"Second";	//中間有偶數個,能全部取完,先取的敗; 
		else cout<<"First";
	}
	return 0;
}