[CodeForces - 197C] C - Lexicographically Maximum Subsequence
C - Lexicographically Maximum Subsequence
You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.
We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.
String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in lines are compared like their ASCII codes.
Input
The single line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 105.
Output
Print the lexicographically maximum subsequence of string s.
Example
ababba
bbba
abbcbccacbbcbaaba
cccccbba
Note
Let's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).
The first sample: aBaBBA
The second sample: abbCbCCaCbbCBaaBA
这个题目就是要求出子串中字典序最大的.
由于本题有许多方法,那我就讲一讲我自己的好了.
由于我们要尽量挑字典序最大的字符作为开头(首关键字并不是长度!),所以,我们要记录当前字符串的最大字符,然后,如果剩下的字符里面,已经不存在这个最大的字符,那么这个字符就下调,知道存在.
这样一个纯模拟的过程就好了,不过不知道为什么我在比赛中时间用的稍微有点多......
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
],nxt[],R[];
],c;
int read(){
,f=; char ch=getchar();
'){if (ch=='-') f=-f; ch=getchar();}
+ch-',ch=getchar();
return x*f;
}
int main(){
scanf("%s",a),len=strlen(a),c='a';
memset(las,,sizeof las);
memset(nxt,,sizeof nxt);
; i>=; i--) ) las[a[i]-'a']=i,nxt[i]=i,R[a[i]-'a']=i;
else nxt[i]=las[a[i]-'a'],las[a[i]-'a']=i;
; i<len; i++) if (c<a[i]) c=a[i];
; i<len; i++) if (a[i]==c){
putchar(c); if (nxt[i]!=i) continue;
);
}
;
}
[CodeForces - 197C] C - Lexicographically Maximum Subsequence的更多相关文章
- Educational Codeforces Round 32 E. Maximum Subsequence
题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往 ...
- Codeforces 888E Maximum Subsequence
原题传送门 E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces 888E - Maximum Subsequence(折半枚举(meet-in-the-middle))
888E - Maximum Subsequence 思路:折半枚举. 代码: #include<bits/stdc++.h> using namespace std; #define l ...
- Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)
题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...
- codeforces 880E. Maximum Subsequence(折半搜索+双指针)
E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #648 (Div. 2) E. Maximum Subsequence Value 贪心
题意:E.Maximum Subsequence Value 题意: 给你n 个元素,你挑选k个元素,那么这个 k 集合的值为 ∑2i,其中,若集合内至少有 max(1,k−2)个数二进制下第 i 位 ...
- 1007. Maximum Subsequence Sum (25)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...
- PAT - 测试 01-复杂度2 Maximum Subsequence Sum (25分)
1, N2N_2N2, ..., NKN_KNK }. A continuous subsequence is defined to be { NiN_iNi, Ni+1N_{i ...
- Maximum Subsequence Sum(接上篇)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...
随机推荐
- js实现类型jq的dom加载完成
有时候我们只想在 dom 加载完成后运行 js ,而不是等所有图片加载完成.所以不需要 onload , onload 会加载图片等其他媒体.很消耗时间. 原:http://blog.csdn.net ...
- 模块、包及常用模块(time/random/os/sys/shutil)
一.模块 模块的本质就是一个.py 文件. 导入和调用模块: import module from module import xx from module.xx.xx import xx as re ...
- 最受欢迎的前端框架 —— Bootstrap学习
Bootstrap是Twitter的Mark Otto和Jacob Thornton开发的,是目前最受欢迎的前端框架,它简单灵活,使得Web前端开发更加快捷方便. 首先,要基本掌握Bootstrap框 ...
- 【Java】【线程】
/* 栗子 通过Runnable接口实现简历线程实例 */ class Dog implements Runnable{ //重写run函数 public void run(){ int times ...
- Pandas 基础(2) - Dataframe 基础
上一节我们已经对 Dataframe 的概念做了一个简单的介绍, 这一节将具体看下它的一些基本用法: 首先, 准备一个 excel 文件, 大致内容如下, 并保存成 .csv 格式. 然后, 在 ju ...
- _itemmod_nopatch、_itemmod_nopatch_level、_itemmod_nopatch_spell、_itemmod_nopatch_src、_itemmod_nopatch_stat、_itemmod_nopatch_stat_prefix
原始物品(_itemmod_nopatch中Entry)需要能够装备 该功能产生的新物品不需要制作dbc 尽量避免配置主动技能(_itemmod_nopatch_spell) _itemmod_nop ...
- go helloworld
// Sample program to show how a bytes.Buffer can also be used // with the io.Copy function. package ...
- Python day2_int以及string的常见方法1_笔记
Python中,主要的基本类型有:数字(int型).字符串(string型).列表(list型).元祖(tuple型).字典(direct型).布尔值(boolean型) 1.int型 1.强转int ...
- .NET Core 管道
从用户发请求到服务器响应返回数据 请求从 Request进去 先经过 Middleware(中间件) 然后经过AuthoriationFilters授权验证(token验证和 多租户验证) 在经 ...
- eslint简单的规范
module.exports = { root: true, parser: 'babel-eslint', parserOptions: { sourceType: 'module' }, // h ...