• Rikka with Game[技巧]----2019 杭电多校第九场:1005


     

    Rikka with Game

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
    Total Submission(s): 0    Accepted Submission(s): 0


    Problem Description
    Though both Rikka and Yuta are busy with study, on their common leisure, they always spend time with each other and sometimes play some interesting games. 

    Today, the rule of the game is quite simple. Given a string s with only lowercase letters. Rikka and Yuta need to operate the string in turns while the first operation is taken by Rikka.

    In each turn, the player has two choices: The first one is to terminate the game, and the second one is to select an index i of s and right shift the value of char si, i.e., ab,bc,,yz,za.

    If the game is still alive after 2101 turns, i.e., after Yuta finishes his 2100 turns, the game will end automatically. The final result is the value of s when the game is over.

    Now, Rikka wants to minimize the lexicographical order of the result while Yuta wants to maximize it. You are required to calculate the result of the game if both Rikka and Yuta play optimally.

    For two string a and b with equal length ma is lexicographically smaller than b if and only if there exists an index i[1,n] which satisfies ai<bi and aj=bj holds for all j[1,i).
    Input
    The first line of the input contains an integer T(1T100), the number of test cases.

    For each test case, the input contains a single line with a single string with only lowercase letters, the initial value of s(1|s|100).

    s(1|s|100).
    Output
    For each test case, output a single line with a single string, the answer.
    Sample Input
    2 a
    zbc
    Sample Output
      a
      bbc
     
     
    思路:
    • 首先,当字符串中y或时,Rikka 应直接停止操作,因为原串就时他能取得的最小串;
    • 当字符串以z开头时,Rikka应将最左边的z拨动到a,此时的串变得更小,而Yuta应将Rikka拨动出的a拨动成b,因为此时b事Yuta能取得的最大串;
    • 当字符串以y开头后面接着z时,Rikka应跳过y去拨动第一个z,此时获得了更小串,注意,此时不能拨动y因为,当Rikka拨动y为z时,Yuta立即停止游戏,Rikka取得的不是最优解,故不符合题意,应跳过y去拨动z为a,Yuta此时应将Rikka拨动的a拨动成b,同第二中情况。
    • 在代码中应表现为,如果字符串没有z则直接返回原串,如果字符串中存在z且z前面没有东西或全是y则,应将第一个z变为b返回;

    代码如下:

    //1005
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    char str[110];int len;
    int main(){
        int t;
        scanf("%d",&t);
        int j;
        while(t--){
            scanf("%s",str);
            len =strlen(str);
            for(j = 0 ; j < len && str[j] == 'y' ;j++);
            if(str[j] == 'z') str[j] = 'b';
            printf("%s
    ",str);
        }
        return 0;
    }
     
  • 相关阅读:
    923c C. Perfect Security
    hdu ACM Steps Section 1 花式A+B 输入输出格式
    我回来了
    POJ–2104 K-th Number
    bzoj1009: [HNOI2008]GT考试
    bzoj1875: [SDOI2009]HH去散步
    1898: [Zjoi2005]Swamp 沼泽鳄鱼
    Hadoop
    程序员的自我修养
    Effective C++笔记
  • 原文地址:https://www.cnblogs.com/zhangxiaomao/p/11378684.html
Copyright © 2020-2023  润新知