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. MySQL 在线开启&关闭GTID模式

    MySQL 在线开启&关闭GTID模式 目录 MySQL 在线开启&关闭GTID模式 基本概述 在线开启GTID 1. 设置GTID校验ENFORCE_GTID_CONSISTENCY ...

  2. Secant 方法求方程多个根

    Secant 方法介绍 Secant Method 函数 Secant_Methods 简介 1.函数定义 [c, errColumn] = Secant_Method(f, a, b, N, con ...

  3. 编程艺术第十六~第二十章:全排列/跳台阶/奇偶调序,及一致性Hash算法

    目录(?)[+]   第十六~第二十章:全排列,跳台阶,奇偶排序,第一个只出现一次等问题 作者:July.2011.10.16.出处:http://blog.csdn.net/v_JULY_v. 引言 ...

  4. MYSQL(3)

    加载C盘下的目录 全表查询 查询部分字段 查询总数 条件过滤 and or 包含 范围检查 between and 否定结果not 匹配任意字符    like 以什么开始^   rlike 以什么结 ...

  5. java中的Arrays类

    今天刚接触了数组,学到了几个比较常用的方法 Fill方法:给数组赋值 sort方法:给数组升序 equals方法:比较数组中元素 值是否相等 binarySearch方法:对排序好的数组进行二分查找法 ...

  6. 日常Java测试第一段 2021/11/12

    课堂测试一 package word_show;import java.io.BufferedReader;import java.io.FileNotFoundException;import ja ...

  7. UBI 文件系统之分区挂载

    Linux 系统中有关mtd和ubi的接口:(1) cat /proc/mtd:可以看到当前系统的各个mtd情况,(2) cat /proc/partitions: 分区信息,有上面的类似(3) ca ...

  8. Qt——error之undefined reference to `vtable for classname

    可能原因:自定义类中使用自定义槽和信号,但是没有在类中增加Q_OBJECT, 解决办法:在类中增加Q_OBJECT,删除编译产生的文件进行重新编译 具体原因分析如下 博主原文

  9. 记录一下使用MySQL的left join时,遇到的坑

    # 现象 left join在我们使用mysql查询的过程中可谓非常常见,比如博客里一篇文章有多少条评论.商城里一个货物有多少评论.一条评论有多少个赞等等.但是由于对join.on.where等关键字 ...

  10. MyBatis中sql实现时间查询的方法

    <if test="startTime != null and startTime !=''"> AND lTime >= #{startTime} </i ...