zoukankan      html  css  js  c++  java
  • UPC-6486 An Ordinary Game(思维)

    题目描述
    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.
    输入
    The input is given from Standard Input in the following format:
    s
    输出
    If Takahashi will win, print First. If Aoki will win, print Second.
    样例输入
    aba
    样例输出
    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.

    题意:给出一个串,两个人轮流从该串中删除字母,若某个字母左右两边字母相同,则不能删除,该串的左右两端字母不能删除。最后不能做操作的人输,问赢的人是谁。

    可以发现,对于任何一个串,如果不是除左右两端外中间每个字母都不能删除的情况,如ABABA等,其余情况都是可以破解的,普遍情况是,最左和最右两端字母不同,那么直接删去中间所有字母,输赢即判断中间字母数量的奇偶性,而左右两端字母相同时,中间字母不能删完,肯定会剩余一个字母,那么除去一个字母之后同样是判断字母数量奇偶性判断输赢。

    #include<bits/stdc++.h>
    #define LL long long
    using namespace std;
    const int maxn=1e5+10;
    int n;
    char a[maxn];
    int main()
    {
        while(scanf("%s",a)!=EOF)
        {
            int ans=0;
            int len=strlen(a);
            for(int i=1; i<len-1; i++)
                if(a[i-1]!=a[i+1])ans++;
            if(ans==0)
            {
                printf("Second
    ");
                continue;
            }
            if(a[0]!=a[len-1])printf("%s
    ",len%2?"First":"Second");
            else printf("%s
    ",len%2?"Second":"First");
        }
    }
    
  • 相关阅读:
    Java实现字符串编辑距离
    Java实现字符串编辑距离
    Java实现字符串编辑距离
    Java实现最大连续乘积子数组
    Java实现最大连续乘积子数组
    Java实现最大连续乘积子数组
    Java实现最大连续乘积子数组
    Java实现最大连续乘积子数组
    Silverlight消散,WinRT登台
    WPF四年,尤不足以替代WinForm
  • 原文地址:https://www.cnblogs.com/kuronekonano/p/11135760.html
Copyright © 2011-2022 走看看