AtCoder Regular Contest 064 ,D An Ordinary Game(博弈,一定会产生某种结果)

题目描述:

                                        D - An Ordinary Game

Time Limit: 2 sec / Memory Limit: 256 MB

Score : 500500 points

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

Copy

aba

Sample Output 1 Copy

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.

Sample Input 2 Copy

Copy

abc

Sample Output 2 Copy

Copy

First

When Takahashi removes b from ss, it becomes ac. Then, Aoki cannot perform the operation, since there is no character in ss, excluding both ends.

Sample Input 3 Copy

Copy

abcab

Sample Output 3 Copy

Copy

First

思路:

        因为最后剩下的串一定是不能再操作的,即删除尽可能多的字符, 

所以如果给出的字符串首位和末尾不同,那么我们肯定可以通过len-2次

操作使得该字符串只剩下首尾两个字符,如果相同,则肯定可以通过一

系列操作使得最后只剩下3个数,既然知道需要去掉几个数,之后由奇偶

性答案也就可以确定了。

代码实现:


#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e5+100;
LL a[N];
vector<char>V;
int main()
{
	string str;
	while(cin>>str)
	{
		int len=str.length();
		if(str[0]==str[len-1])
		{
			int tmp=len-2-1;
			if(tmp&1)
			{
				cout<<"First"<<endl;
			}
			else
			{
				cout<<"Second"<<endl;
			}
		}
		else
		{
			int tmp=len-2;
			if(tmp&1)
			{
				cout<<"First"<<endl;
			}
			else
			{
				cout<<"Second"<<endl;
			}
		}
		
	}
	
	return 0;
} 

The end;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值