概述
1005: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1005&cid=856
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., a→b,b→c,…,y→z,z→a.
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 m, a 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(1≤T≤100), 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).
Output
For each test case, output a single line with a single string, the answer.
Sample Input
2
a
zbc
Sample Output
a
bbc
解题思路:
这道题目需要分几种情况进行讨论;首先我们需要知道的是在正常情况下,第一个人最优秀的状
1态是全是b的情况,第二个人最理想的情况是全是y的情况;想清楚 这点后我们就可以分几种昂情况进行讨论。
1.第一个字符是z,那么直接把第一个字符变成b ,然后直接输出。
2.第一个字符不是’z’, 那么我们就要找到从第一个字符开始第一个不是‘y’的字符,若这个字符是‘z’,那么就把他改成‘b’, 否则直接输出。
AC代码:
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main() {
// freopen("in.txt", "r", stdin);
int t;
char str[150];
scanf("%d", &t);
while(t--) {
scanf("%s", &str);
int f = 0;
if(str[0] == 'z') {
str[0] = 'b';
} else {
for(int i = 0; i < strlen(str); i ++)
if(str[i] != 'y') {
if(str[i] == 'z') {
str[i] = 'b';
}
break;
}
}
printf("%sn", str);
}
return 0;
}
总结:
这次比赛,明显感觉到自己的积累还是不够,一些题目的思路也还是想的不够快,导致最后有思路的题目,没有时间写了;还需要继续的训练;另外还需要再去促进队友之间的合作,我觉得和队友之间讨论题目的感觉很好,有利于促进正确思路的想出,但是在讨论的同时还需要进行有深度的思考。
对于这道题目,刚开始有最开始的想法,但是不够全面,导致这道题目wa了2发,下一次即使想出来了,还是要强迫自己再想5分钟,看还有没有漏洞,我觉得这点也比较重要。
最后
以上就是美满野狼为你收集整理的2019杭电多校第九次的全部内容,希望文章能够帮你解决2019杭电多校第九次所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复