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
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).
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).
a
- 首先,当字符串中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的更多相关文章
- 2018 Multi-University Training Contest 9 杭电多校第九场 (有坑待补)
咕咕咕了太久 多校博客直接从第三场跳到了第九场orz 见谅见谅(会补的!) 明明最后看下来是dp场 但是硬生生被我们做成了组合数专场…… 听说jls把我们用组合数做的题都用dp来了遍 这里只放了用组 ...
- Rikka with Travels(2019年杭电多校第九场07题+HDU6686+树形dp)
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 定义\(L(a,b)\)为结点\(a\)到结点\(b\)的路径上的结点数,问有种\(pair(L(a,b),L(c,d))\)取值,其中结点\ ...
- 2019杭电多校第⑨场B Rikka with Cake (主席树,离散化)
题意: 给定一块n*m的矩形区域,在区域内有若干点,每个顶点发出一条射线,有上下左右四个方向,问矩形被分成了几个区域? 思路: 稍加观察和枚举可以发现,区域数量=射线交点数+1(可以用欧拉定理验证,但 ...
- 杭电多校第九场 hdu6424 Rikka with Time Complexity 数学
Rikka with Time Complexity Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K ( ...
- 杭电多校第九场 hdu6425 Rikka with Badminton 组合数学 思维
Rikka with Badminton Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/O ...
- 杭电多校第九场 HDU6415 Rikka with Nash Equilibrium dp
Rikka with Nash Equilibrium Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K ...
- 杭电多校第九场 D Rikka with Stone-Paper-Scissors 数学
Rikka with Stone-Paper-Scissors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/52428 ...
- 2019杭电多校第一场hdu6581 Vacation
Vacation 题目传送门 update(O(n)) 看了那个O(n)的方法,感觉自己想的那个O(nlogn)的好傻,awsl. 0车最终通过停车线的时候,状态一定是某个车堵住后面的所有车(这个车也 ...
- 2019杭电多校第二场hdu6601 Keen On Everything But Triangle
Keen On Everything But Triangle 题目传送门 解题思路 利用主席树求区间第k小,先求区间内最大的值,再求第二大,第三大--直到找到连续的三个数可以构成一个三角形.因为对于 ...
随机推荐
- free()函数释放一段分配的内存之陷阱
朋友们对malloc函数应该是比较熟悉了,此函数功能是分配一段内存地址,并且将内存地址给一个指针变量,最后记得再调用free函数释放这段内存地址就可以了,标准的流程对吧,好像没什么问题.但是按照此标准 ...
- 20141126-传智播客.NET3.2版
- TigerGraph入门
测试机器配置 1G内存,1个核,CentOS Linux release 7.4.1708 (Core)的云主机,一块50G HDD的云主机. 1. 安装 下载了目前最新的开发者版本,下载链接:htt ...
- Ubuntu系统安装QQ等软件
1.安装deepin-wine环境:上https://github.com/wszqkzqk/deepin-wine-for-ubuntu页面下载zip包(或用git方式克隆),解压到本地文件夹,在文 ...
- 如何在 Centos7 中安装 gcc
系统环境:Centos7.4 今天在安装 Nodejs8.7 的时候,报了一个警告: WARNING: C++ Compiler too old, need g++ 4.9.4 or clang++ ...
- Shiro权限管理框架(二):Shiro结合Redis实现分布式环境下的Session共享
首发地址:https://www.guitu18.com/post/2019/07/28/44.html 本篇是Shiro系列第二篇,使用Shiro基于Redis实现分布式环境下的Session共享. ...
- 【Algorithm】插入排序法
通常人们整理桥牌的方法是一张一张的来,将每一张插入到其他已经有序的牌中的适当位置. • 思想:每步将一个待排序的记录,按其顺序码大小插入到前面已经排序的序列的合适位置,直到全部插入排序完为止. Jav ...
- SQL注入详解及技巧
Tip小技巧 :在白盒测试的过程中,在sql语句的下一句加上 echo $sql. '<br>'; 可以在页面中输出完整的sql语句 效果图 :
- 机房ping监控 smokeping+prometheus+grafana(续) 自动获取各省省会可用IP
一.前言 1.之前的文章中介绍了如何使用smokeping监控全国各省的网络情况:https://www.cnblogs.com/MrVolleyball/p/10062231.html 2.由于之前 ...
- 内容汇总(c语言)
一,内容 常量(整型,浮点型,字符型,字符串型,符号常量) 变量(基本类型:整形,浮点型,字符型,枚举型:构造类型:数组,结构体,共用体:另外还有指针类型和NULL) 顺序结构 分支结构 循环结构 当 ...