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. Svelte入门——Web Components实现跨框架组件复用

    Svelte 是构建 Web 应用程序的一种新方法,推出后一直不温不火,没有继Angular.React和VUE成为第四大框架,但也没有失去热度,无人问津.造成这种情况很重要的一个原因是,Svelte ...

  2. AtCoder Grand Contest 055 题解

    A 赛时直到最后 10min 才做出这个 A 题,之前猜了一个结论一直没敢写,本来不抱啥希望 AC 的结果比赛结束时交了一发竟然 A 了,由此可见我的水平之菜/dk 考虑每次取出字符串开头字符,不妨设 ...

  3. 61. Binary Tree Inorder Traversal

    Binary Tree Inorder Traversal My Submissions QuestionEditorial Solution Total Accepted: 123484 Total ...

  4. kubectl logs查看日志时出现failed to create fsnotify watcher: too many open files

    因为系统默认的 fs.inotify.max_user_instances=128 太小,在查看日志的pod所在节点重新设置此值: 临时设置 sudo sysctl fs.inotify.max_us ...

  5. 基于MQTT协议实现远程控制的"智能"车

    智能,但不完全智能 虽然我不觉得这玩意儿有啥智能的,但都这么叫就跟着叫喽. 时隔好几天才写的 其实在写这篇博文的时候我已经在做升级了,并且已经到了中后期阶段了. 主要是业余时间做着玩,看时间了. 规格 ...

  6. 转 Android 多线程:手把手教你使用AsyncTask

    转自:https://www.jianshu.com/p/ee1342fcf5e7 前言 多线程的应用在Android开发中是非常常见的,常用方法主要有: 继承Thread类 实现Runnable接口 ...

  7. Android 高级UI组件(一)GridView与ListView

    1.GridView 1.GridView学习 GridView和ListView都是比较常用的多控件布局,而GridView更是实现九宫图的首选 main.xml: <?xml version ...

  8. 【Linux】【Services】【VersionControl】Git基础概念及使用

    1. 简介 1.1. 版本控制工具: 本地版本控制系统: 集中化版本控制系统:CVS,SVN 分布式版本控制系统: BitKeeper,Git 1.2. 官方网站: https://git-scm.c ...

  9. zabbix之模板制作(memcache redis)

    #:找一台主机安装redis和memcached(记得安装zabbix-agent) root@ubuntu:~# apt install redis root@ubuntu:~# apt insta ...

  10. SpringBoot(2):运行原理

    一. pom.xml 进入父项目,这里才是真正管理SpringBoot应用里面所有依赖版本的地方,SpringBoot的版本控制中心:以后我们导入依赖默认是不需要写版本:但是如果导入的包没有在依赖中管 ...