CF999C Alphabetic Removals 题解
Content
给定一个长度为 \(n\) 的仅含小写字母的字符串,执行 \(k\) 次如下操作:
- 如果字符串中有
a这个字母,删除从左往右第一个a,并结束操作,否则继续操作; - 如果字符串中有
b这个字母,删除从左往右第一个b,并结束操作,否则继续操作; - 以此类推,如果所有字母都按照如上方式删除完了,那么结束操作。
现在请你求出操作后的字符串。
数据范围:\(1\leqslant n,k\leqslant 4\times 10^5\)。
Solution
直接从左往右扫过去,按照上面的方式删除每个字母,直到删除完 \(k\) 个字符为止即可。
Code
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
using namespace std;
string s;
int n, k, vis[400007];
char cur = 'a';
int main() {
scanf("%d%d", &n, &k);
cin >> s;
while(1) {
int flag = 1;
for(int i = 0; i < n; ++i)
if(s[i] == cur) {
vis[i] = 1;
k--;
if(!k) {flag = 0; break;}
}
if(!flag) break;
cur++;
}
for(int i = 0; i < n; ++i)
if(!vis[i]) printf("%c", s[i]);
return 0;
}
CF999C Alphabetic Removals 题解的更多相关文章
- CF999C Alphabetic Removals 思维 第六道 水题
Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- code forces 999C Alphabetic Removals
C. Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- CodeForces - 999C Alphabetic Removals
C - Alphabetic Removals ≤k≤n≤4⋅105) - the length of the string and the number of letters Polycarp wi ...
- C - Alphabetic Removals
题目链接: You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove e ...
- Alphabetic Removals(模拟水题)
You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly ...
- CoderForces999C-Alphabetic Removals
C. Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- [codeforces] 暑期训练之打卡题(三)
每个标题都做了题目原网址的超链接 Day21<Alphabetic Removals> 题意: 给定一个字符串,要求按照字典序按照出现的前后顺序删除 k 个字母 题解: 记录字符串中各个字 ...
- Word Ladder II leetcode java
题目: Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) ...
- Word Ladder leetcode java
题目: Given two words (start and end), and a dictionary, find the length of shortest transformation se ...
随机推荐
- C#中的异步
什么是异步? 作为一名Web端的码农,第一次接触异步是Ajax. 异步请求后端获取数据源,js操作html的dom节点,而无需要渲染整个网页的操作. 页面上点击按钮,加载进度动画,同时发起Ajax请求 ...
- Atcoder Regular Contest 125 E - Snack(最小割转化+贪心)
Preface: 这是生平第一道现场 AC 的 arc E,也生平第一次经历了 performance \(\ge 2800\),甚至还生平第一次被 hb 拉到会议里讲题,讲的就是这个题,然鹅比较尬 ...
- RSA,DSA,ECDSA,EdDSA和Ed25519的区别
RSA,DSA,ECDSA,EdDSA和Ed25519的区别 用过ssh的朋友都知道,ssh key的类型有很多种,比如dsa.rsa. ecdsa.ed25519等,那这么多种类型,我们要如何选择呢 ...
- Linux内网时钟同步问题(ntp和chrony)
我们都知道时钟同步可以使用外网服务器,在内网内不能连接外网的时候也需要时钟同步,那怎么进行呢? 选择内网的一台稳定的服务器作为时钟源,然后让其他机器都来同步这台机器即可. 注:其实ntp服务和chro ...
- Python三元表达式,列表推导式,字典生成式
目录 1. 三元表达式 2. 列表推导式 3. 字典生成式 3.1 字典生成式 3.2 zip()方法 1. 三元表达式 """ 条件成立时的返回值 if 条件 else ...
- 浏览器点击URL的响应过程
原文:http://igoro.com/archive/what-really-happens-when-you-navigate-to-a-url/ 作为一个软件开发者,你一定会对网络应用如何工作有 ...
- 在Linux下搭建nRF51822的开发烧写环境(makefile版)
http://www.qingpingshan.com/m/view.php?aid=394836
- jsp的动态包含和静态包含
jsp的动态包含和静态包含 例如:提取一个公共的页面(top.jsp)到/WEB-INF/jsp/common/目录下 动态包含: 被包含的页面也会独立编译,生成字节码文件,一般包含页面信息频繁变化的 ...
- A Child's History of England.33
To strengthen his power, the King with great ceremony betrothed his eldest daughter Matilda, then a ...
- acid, acknowledge, acquaint
acid sulphuric|hydrochloric|nitric|carbolic|citric|lactic|nucleic|amino acid: 硫|盐|硝|碳|柠檬|乳|核|氨基酸 王水是 ...