Two Operations Gym - 102263M 优先队列水题
Two Operations Gym - 102263M
Ayoub has a string SS consists of only lower case Latin letters, and he wants you to make some operations on it:
- you can swap any two characters in the string.
- you can delete any two adjacent characters that have the same value and replace them with the next character alphabetically,for example string "abbx""abbx" could be "acx""acx" after one operation, string "zz""zz" could not be changed; because z is the last character in the English alphabets.
Ayoub wants you to make the string lexicographically maximal using the mentioned operations as many times as you want, can you help him?
String x=x1x2...x|x|x=x1x2...x|x| is lexicographically larger than string y=y1y2...y|y|y=y1y2...y|y|, if either |x|>|y||x|>|y| and x1=y1,x2=y2,...,x|y|=y|y|x1=y1,x2=y2,...,x|y|=y|y|, or exists such number r(r<|x|,r<|y|)r(r<|x|,r<|y|), that x1=y1,x2=y2,...,xr=yrx1=y1,x2=y2,...,xr=yr and xr+1>yr+1xr+1>yr+1. Characters in lines are compared like their ASCII codes.
Input
The input contains a single string SS (1≤|S|≤105)(1≤|S|≤105).
It is guaranteed that string SS consists of only lower case Latin letters.
Output
print the lexicographically maximal string that could be obtained using these two operations.
#include<algorithm>
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std; priority_queue <char, vector<char>, greater<char> >q1;//从小到大优先排序
priority_queue <char, vector<char>, less<char> >q2;//从大到小优先排序
int main()
{
string s;
cin >> s;
for (int i = ; i < s.size(); i++) {
q1.push(s[i]);
}
while (!q1.empty()) {
char top = q1.top();//获取栈顶
q1.pop();
if (!q1.empty() && top != 'z') {
if (top == q1.top()) {//合并插入
q1.pop();
q1.push(top + );
}
else {
q2.push(top);
}
}
else {
q2.push(top);
}
}
while (!q2.empty()) {
char head = q2.top();
q2.pop();
cout << head;
}
return ;
}
Two Operations Gym - 102263M 优先队列水题的更多相关文章
- Codeforces Gym 100531G Grave 水题
Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...
- UVaLive 6591 && Gym 100299L Bus (水题)
题意:略. 析:不解释,水题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include < ...
- Codeforces Gym 100286I iSharp 水题
Problem I. iSharpTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- CodeForces Gym 100685C Cinderella (水题)
题意:给定 n 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...
- Argus UVALive - 3135(优先队列 水题一道)
有一系列的事件,它每Period秒钟就会产生编号为qNum的事件,你的任务是模拟出前k个事件,如果多个事件同时发生,先处理qNum小的事件 今天再看看数据结构.. #include <iostr ...
- Gym 100531G Grave(水题)
题意:给定一个大矩形,再给定在一个小矩形,然后给定一个新矩形的长和高,问你能不能把这个新矩形放到大矩形里,并且不与小矩形相交. 析:直接判定小矩形的上下左右四个方向,能不能即可. 代码如下: #pra ...
- codeforces Gym 100187L L. Ministry of Truth 水题
L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
- 水题 Gym 100553K Knockout Racing
题目传送门 /* 题意:有若干个点在一个区间内来回移动,1m/s. 水题:n^2的复杂度能解决,注意时间可能大于一个周期,要取模 */ #include <cstdio> #include ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
随机推荐
- SpringCloud(七)超时、重试
一.Ribbon(单独配置) 可以通过ribbon.xx来进行全局配置.也可以通过服务名.ribbon.xx来对指定服务配置 全局配置: ribbon: ConnectTimeout: 3000 #连 ...
- APT32入侵我国,试图窃取COVID-19相关情报
新闻一篇: 一直以来,APT32都以东南亚为攻击目标,并且是近几年来针对中国大陆进行攻击活动最活跃的APT攻击组织,没有之一.此次再将目标对准中国,与新冠疫情离不开关系. 4月22日,Fireye发布 ...
- MySQL笔记总结-DQL语言
DQL语言 基础查询 一.语法 select 查询列表 from 表名; 二.特点 1.查询列表可以是字段.常量.表达式.函数,也可以是多个 2.查询结果是一个虚拟表 三.示例 1.查询单个字段 se ...
- JasperReports入门教程(二):中文打印
JasperReports入门教程(二):中文打印 背景 在上一篇中我们介绍了JasperReport的基本入门,也展示了一个报表.但是我们的示例都是使用的英文,如果我们把需要打印的数据改为中文会怎么 ...
- Python Flask构建微信小程序订餐系统 学习 资源
一.Flask MVC框架结构 1.1实际项目结构 1.2application.py 项目配置文件Flask之flask-script模块使用 static.py 文件(部署到生成环境不需 ...
- python机器学习的常用算法
Python机器学习 学习意味着通过学习或经验获得知识或技能.基于此,我们可以定义机器学习(ML)如下 - 它可以被定义为计算机科学领域,更具体地说是人工智能的应用,其为计算机系统提供了学习数据和从经 ...
- 用python把技术文档中,每个模块系列截图生成一个动态GIF
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 最近在写技术文档的时候,发现一个问题.对于每个技术步骤,都需要一个截图,这 ...
- php 超全局变量(整理)
来源:https://www.cnblogs.com/wsybky/p/8745286.html 一.$GLOBALS 在GLOBALS数组中,每一个变量为一个元素,键名对于变量名,值对于变量的内. ...
- [Qt] 默认的槽函数 例如 on_pushButton_clicked()
在 setupUI 函数里有一句: QMetaObject::connectSlotsByName(QWDialog); 它假设槽函数的名称是 void on_<object name>_ ...
- UVALive 7509 Dome and Steles
三分 #include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<=b;++i) #d ...