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 题解的更多相关文章

  1. CF999C Alphabetic Removals 思维 第六道 水题

    Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. code forces 999C Alphabetic Removals

    C. Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  3. CodeForces - 999C Alphabetic Removals

    C - Alphabetic Removals ≤k≤n≤4⋅105) - the length of the string and the number of letters Polycarp wi ...

  4. C - Alphabetic Removals

    题目链接: You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove e ...

  5. Alphabetic Removals(模拟水题)

    You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly ...

  6. CoderForces999C-Alphabetic Removals

    C. Alphabetic Removals time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. [codeforces] 暑期训练之打卡题(三)

    每个标题都做了题目原网址的超链接 Day21<Alphabetic Removals> 题意: 给定一个字符串,要求按照字典序按照出现的前后顺序删除 k 个字母 题解: 记录字符串中各个字 ...

  8. Word Ladder II leetcode java

    题目: Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) ...

  9. Word Ladder leetcode java

    题目: Given two words (start and end), and a dictionary, find the length of shortest transformation se ...

随机推荐

  1. 在安卓开发中需要格式化桌面icon图标

    使用以下在线工具即可实现http://www.makeicon.cc/home/index

  2. 爬虫——正则表达式爬取豆瓣电影TOP前250的中英文名

    正则表达式爬取豆瓣电影TOP前250的中英文名 1.首先要实现网页的数据的爬取.新建test.py文件 test.py 1 import requests 2 3 def get_Html_text( ...

  3. Linux下Zabbix5.0 LTS + Grafana8.2.2图形可视化

    Grafana是一款开源的可视化软件,可以搭配数据源实现一个数据的展示和分析:Grafana功能强大,有着丰富的插件,但Grafana默认没有zabbix作为数据源,需要手动给zabbix安装一个插件 ...

  4. DVWA总结

    Brute Force,即暴力(破解),是指黑客利用密码字典,使用穷举法猜解出用户口令,是现在最为广泛使用的攻击手法之一,如2014年轰动全国的12306"撞库"事件,实质就是暴力 ...

  5. LGV 引理小记

    讲个笑话,NOI 之前某场模拟赛让我知道了这个神奇的科技,于是准备 NOI 之前学完,结果鸽着鸽着就鸽掉了,考 day1 之前一天本来准备花一天时间学的,然后我就开玩笑般地跟自己说,这么 trivia ...

  6. 洛谷 P4484 - [BJWC2018]最长上升子序列(状压 dp+打表)

    洛谷题面传送门 首先看到 LIS 我们可以想到它的 \(\infty\) 种求法(bushi),但是对于此题而言,既然题目出这样一个数据范围,硬要暴搜过去也不太现实,因此我们需想到用某种奇奇怪怪的方式 ...

  7. Codeforces Round #681 (Div. 1) Solution

    A. Extreme Subtraction 把这个数组差分一下,发现操作一的作用是把 \(d_1\) 的大小分给 \(d_i\),而操作二的作用是把 \(d_i\) 减去任意值,目标是把 \(d\) ...

  8. 【机器学习与R语言】7-回归树和模型树

    目录 1.理解回归树和模型树 2.回归树和模型树应用示例 1)收集数据 2)探索和准备数据 3)训练数据 4)评估模型 5)提高模型性能 1.理解回归树和模型树 决策树用于数值预测: 回归树:基于到达 ...

  9. vector去重--unique

    具体实现见中间源码 function template <algorithm> std::unique equality (1) template <class ForwardIte ...

  10. mysql数据操作语言DML

    插入insert 插入方式1 语法: insert into 表名(列名,....) values(值1,....) 说明: 1.插入的值的类型要与列的类型一致或兼容 2.可以为null的值:①列写了 ...