An Ordinary Game(AtCoder-2153)

Problem Description

There is a string s of length 3 or greater. No two neighboring characters in s 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 s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s.
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|≤105
  • s consists of lowercase English letters.
  • No two neighboring characters in s are equal.

Input

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

s

Output

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

Example

Sample Input 1

aba

Sample Output 1

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

Sample Input 2

abc

Sample Output 2

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

Sample Input 3

abcab

Sample Output 3

First

题意:给出一个任意相邻字符不相同的字符串,两个人轮流在字符串中删出一个字符,不能删除字符串两端的字符,如果在删除一个字符串后,使得字符串中有相邻两个字符相同,那么当前删除这个字符的人输了,问最后谁能取胜

思路:

由于任意两个字符不相同,那么只需考虑除去字符串两端的 len-2 个字符,由于两人都足够聪明,那么这些字符一定是可以删完的

但因为字符串两端的字符不能删除,那么就要考虑到删除中间的字符后是否两端的字符是否相同:

  • 如果两端字符相同:那么中间字符串的最后一个不能删,,故若中间字符串为奇数时,第二个人一定赢,中间字符串为偶数时,第一个人一定赢
  • 如果两端字符不同:那么中间字符串的最后一个可以删,故若中间字符串为奇数时,第一个人一定赢,中间字符串为偶数时,第二个人一定赢

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
char str[N];
int main() {
    scanf("%s",str);
    int len=strlen(str);

    int num=len-2;
    if(str[0]!=str[len-1]){
        if(num%2)
            printf("First\n");
        else
            printf("Second\n");
    }
    else{
        if(num%2)
            printf("Second\n");
        else
            printf("First\n");
    }

    return 0;
}

 

posted @ 2022-09-20 22:55  老程序员111  阅读(22)  评论(0)    收藏  举报