D - An Ordinary Game(博弈)

    xiaoxiao2022-07-13  177

    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|≤105ss 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

    题意:

    给你一个字符(任意相邻的两个字符都不相同)两个人进行博弈,每个人只能从中间去(最左边和最右边的不能取)取这个字符要保证去取完之后任意相邻的两个字符串都不相同,否则这个字符就不能取。问最后谁能获胜。

    思路:

    如果两端的字符不相等(那么中间的字符能取完)。如果两端的相等中间的字符要生一个不能取。

    然后分奇数偶数讨论就行了。

    代码:

    #include<bits/stdc++.h> using namespace std; char s[100009]; int main() { scanf("%s",&s); int n=strlen(s); if(s[0]==s[n-1]) { n--; } if(n%2==1) { cout<<"First"<<endl; } else { cout<<"Second"<<endl; } }

     

    最新回复(0)