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. Ubuntu 软件安装

    apt 使用apt安装,需要sudo 一些命令: sudo apt-get install git deb deb软件安装方法: sudo dpkg -I xxxx.deb 我们在Windows下安装 ...

  2. 从零开始学Kotlin第四课

    面向对象: //妹子 性格 声音 class Girl(var chactor:String,var voice:String) fun main(args: Array<String>) ...

  3. 从ApacheTomcat架构谈面试到源码编译环境v10.0.12

    概述 开启博客分享已近三个月,感谢所有花时间精力和小编一路学习和成长的伙伴们,有你们的支持,我们继续再接再厉 **本人博客网站 **IT小神 www.itxiaoshen.com 定义 Tomcat官 ...

  4. 撸了一个可调试 gRPC 的 GUI 客户端

    前言 平时大家写完 gRPC 接口后是如何测试的?往往有以下几个方法: 写单测代码,自己模拟客户端测试. 可以搭一个 gRPC-Gateway 服务,这样就可以在 postman 中进行模拟. 但这两 ...

  5. 多线程Reactor模式

    目录 1.1 主服务器 2.1 IO请求handler+线程池 3.1 客户端 多线程Reactor模式旨在分配多个reactor每一个reactor独立拥有一个selector,在网络通信中大体设计 ...

  6. CF1550D Excellent Arrays

    考虑每个数一定是这个形式: \(i + x,i - x\) 所以如果我们要构造一个最大的数组. 那一定是这样的形式: 有一半为\(i + x\),有一半\(i - x\) 那么我们发现每个数有这样一个 ...

  7. P7327 Dream and Discs

    题目传送门. 题意简述:有 \(n\) 个数 \(a_1,a_2,\cdots a_n\),等概率选取区间 \(P_1,S_1\subseteq [1,n]\),\(P_2\subseteq P_1\ ...

  8. [R] 保存pheatmap图片对象到文件

    一般我们使用pheatmap通过Rstudio交互得到的图片在plots的Export导出即可,如何保存对象到文件呢?这个需求在自动化流程中很常见,作者似乎也没说明. 生成示例数据: test = m ...

  9. Python3编译安装ssl模块问题

    本文以Centos系统为例 1.确保linux系统中安装了ssl-devel包 2.编译安装ssl模块到Python3中 1.查看linux系统中是否安装了ssl-devel包 # 查看命令 rpm ...

  10. Redis | Redis常用命令及示例总结(API)

    目录 前言 1. Key(键) 1.1 键的基本操作功能 del move sort rename renamenx migrate 1.2 键的获取功能 type exists randomkey ...