题目描述:
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:
ssOutput
If Takahashi will win, print
First
. If Aoki will win, printSecond
.Sample Input 1 Copy
Copy
abaSample Output 1 Copy
Copy
SecondTakahashi, 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 ssbecomingaa
, with twoa
s neighboring.Sample Input 2 Copy
Copy
abcSample Output 2 Copy
Copy
FirstWhen Takahashi removes
b
from ss, it becomesac
. Then, Aoki cannot perform the operation, since there is no character in ss, excluding both ends.Sample Input 3 Copy
Copy
abcabSample 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;