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).
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返回;

代码如下:

//
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char str[];int len;
int main(){
int t;
scanf("%d",&t);
int j;
while(t--){
scanf("%s",str);
len =strlen(str);
for(j = ; j < len && str[j] == 'y' ;j++);
if(str[j] == 'z') str[j] = 'b';
printf("%s\n",str);
}
return ;
}

Rikka with Game[技巧]----2019 杭电多校第九场:1005的更多相关文章

  1. 2018 Multi-University Training Contest 9 杭电多校第九场 (有坑待补)

    咕咕咕了太久  多校博客直接从第三场跳到了第九场orz 见谅见谅(会补的!) 明明最后看下来是dp场 但是硬生生被我们做成了组合数专场…… 听说jls把我们用组合数做的题都用dp来了遍 这里只放了用组 ...

  2. Rikka with Travels(2019年杭电多校第九场07题+HDU6686+树形dp)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 定义\(L(a,b)\)为结点\(a\)到结点\(b\)的路径上的结点数,问有种\(pair(L(a,b),L(c,d))\)取值,其中结点\ ...

  3. 2019杭电多校第⑨场B Rikka with Cake (主席树,离散化)

    题意: 给定一块n*m的矩形区域,在区域内有若干点,每个顶点发出一条射线,有上下左右四个方向,问矩形被分成了几个区域? 思路: 稍加观察和枚举可以发现,区域数量=射线交点数+1(可以用欧拉定理验证,但 ...

  4. 杭电多校第九场 hdu6424 Rikka with Time Complexity 数学

    Rikka with Time Complexity Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K ( ...

  5. 杭电多校第九场 hdu6425 Rikka with Badminton 组合数学 思维

    Rikka with Badminton Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/O ...

  6. 杭电多校第九场 HDU6415 Rikka with Nash Equilibrium dp

    Rikka with Nash Equilibrium Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K ...

  7. 杭电多校第九场 D Rikka with Stone-Paper-Scissors 数学

    Rikka with Stone-Paper-Scissors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/52428 ...

  8. 2019杭电多校第一场hdu6581 Vacation

    Vacation 题目传送门 update(O(n)) 看了那个O(n)的方法,感觉自己想的那个O(nlogn)的好傻,awsl. 0车最终通过停车线的时候,状态一定是某个车堵住后面的所有车(这个车也 ...

  9. 2019杭电多校第二场hdu6601 Keen On Everything But Triangle

    Keen On Everything But Triangle 题目传送门 解题思路 利用主席树求区间第k小,先求区间内最大的值,再求第二大,第三大--直到找到连续的三个数可以构成一个三角形.因为对于 ...

随机推荐

  1. ubuntu18.04安装nvidia驱动总结经验

    本人电脑是 DELL Inspiron 3670, 系统装的是ubuntu18.04, 显卡使用的是GeForce GTX 1050 Ti, 在安装nividia显卡的时候花费两天时间,感受颇深,顾总 ...

  2. 从似然函数到EM算法(附代码实现)

    1. 什么是EM算法 最大期望算法(Expectation-maximization algorithm,又译为期望最大化算法),是在概率模型中寻找参数最大似然估计或者最大后验估计的算法,其中概率模型 ...

  3. 基于 HTML5 WebGL 的民航客机飞行监控系统

    前言 前些日子出差,在飞机上看到头顶的监控面板,除了播放电视剧和广告之外,还会时不时的切换到一个飞机航行的监控系统,不过整个监控系统让人感到有一点点的简陋,所以我就突发奇想制作了一个采用 HT for ...

  4. 简单web网页与SSM后台交互

    简单web网页与SSM后台交互 情况说明 如今,已经搭建好SSM后台开发环境,并且可以经由postman工具测试成功.现在尝试写出web前端网页,通过实现简单的提交.注册.查询功能来加深对前后端数据传 ...

  5. Oracle导入dump文件

    imp USER/PASSWORD@host/DB_name file=xxx.dmp(path) full=y ignore=y

  6. 手动创建MySQL服务

    1.复制一份MySQL服务文件,放入一个路径 2.清理data文件夹下文件,仅保留mysql等 3.修改my.ini,port,...dir等配置 4.管理员运行cmd,cd>bin:mysql ...

  7. spring与actionMQ整合

    出处:http://www.cnblogs.com/leiOOlei/p/5075402.html 一.配置部分 ActiveMQ的安装这就不说了,很简单, 这个例子采用maven构建,首先看一下po ...

  8. spring读取xml配置文件(二)

    一.当spring解析完配置文件名的占位符后,就开始refresh容器 @Override public void refresh() throws BeansException, IllegalSt ...

  9. BFS(宽度优先搜索) -例题

    原题地址 https://vjudge.net/contest/313171     密码:algorithm A - Rescue Angel was caught by the MOLIGPY! ...

  10. Python基础总结之第九天开始【python之OS模块对目录的操作、以及操作文件】(新手可相互督促)

    年薪20万的梦想...         python对文件.目录能做什么?或者说我们需要python替我们做什么?最经常的操作就是对文件的:打开.关闭.读取.写入.修改.保存等等对目录的操作,无非就是 ...