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).
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).

For each test case, output a single line with a single string, the answer.


Sample Input
2 a
Sample Output
  • 首先,当字符串中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返回;


using namespace std;
char str[110];int len;
int main(){
    int t;
    int j;
        len =strlen(str);
        for(j = 0 ; j < len && str[j] == 'y' ;j++);
        if(str[j] == 'z') str[j] = 'b';
    return 0;



posted @ 2019-08-19 18:04  我不是张小毛  阅读(...)  评论(...编辑  收藏