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 ...
随机推荐
- 多声部处理细节之crossstaff音符处理
下面给出这几个案例的代码 ,可直接粘贴编译. \version "2.20.0" \language "english" \paper { #(set-pape ...
- 从零开始学Kotlin第三课
kotlin函数和函数式表达式的简化写法: fun main(args:Array<String>) { var result=add(2,5) println(result) ///简化 ...
- IDEA 注释模板配置
配置创建类的注释模板 Ctrl + Shift + a --> File and Code Templates // 快捷定位配置 // 路径:File --> Settings --&g ...
- Nginx编译安装相关参数
Nginx编译安装相关参数 Nginx插件安装 ------------------pcre------------------ cd /usr/local/source wget http://ww ...
- fatal error: runtime: out of memory
[root@VM_0_10_centos frp_0.27.0_linux_amd64]# top top - 21:09:19 up 2 days, 4 min, 2 users, load ave ...
- Hive-删除表(drop、truncate的区别)
Hive删除操作主要分为几大类:删除数据(保留表).删除库表.删除分区.我将以下图为例清空iot_devicelocation中的数据,之后再删除表.库等. 解释: use xpu123; #使用 ...
- Requests的安装和使用
一.Requests的安装1.pip3 install requests2.验证 import requests 不报错即可
- EDA简介
Electronic design automation (EDA), also referred to as electronic computer-aided design (ECAD),[1] ...
- 位运算符在JS中的妙用
正文 位运算 JavaScript 中最臭名昭著的 Bug 就是 0.1 + 0.2 !== 0.3,因为精度的问题,导致所有的浮点运算都是不安全的,具体原因可详见<0.1 + 0.2不等于0. ...
- Templates and Default Arguments
Default parameters for templates in C++: Like function default arguments, templates can also have de ...