D. Dense Subsequence

题目连接:

http://codeforces.com/contest/724/problem/D

Description

You are given a string s, consisting of lowercase English letters, and the integer m.

One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.

Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.

Formally, we choose a subsequence of indices 1 ≤ i1 < i2 < ... < it ≤ |s|. The selected sequence must meet the following condition: for every j such that 1 ≤ j ≤ |s| - m + 1, there must be at least one selected index that belongs to the segment [j,  j + m - 1], i.e. there should exist a k from 1 to t, such that j ≤ ik ≤ j + m - 1.

Then we take any permutation p of the selected indices and form a new string sip1sip2... sipt.

Find the lexicographically smallest string, that can be obtained using this procedure.

Input

The first line of the input contains a single integer m (1 ≤ m ≤ 100 000).

The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string s.

Output

Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.

Sample Input

3

cbabc

Sample Output

a

Hint

题意

给你一个m和一个字符串s

一开始你的now为0,你需要在[now,now+m-1]里面选一个字符,假设选的位置为p,则now=p+1,然后重复

直到now+m-1>=s.size(),并且不能选择使得字典序变得更小的时候,就不选了。

你需要找到字典序最小的答案,答案最后可以排序,选出来的东西。

题解:

暴力枚举最大的字符是什么,然后再贪心的去放,小于这个字符的全选,其他的贪心的去放,使得能够覆盖所有区域。

肯定是放覆盖当前区间最后面的那个。

代码

#include<bits/stdc++.h>
using namespace std; set<int>S[26];
int m;
string s;
int cnt[26];
int main()
{
cin>>m>>s;
for(int i=0;i<26;i++)
{
int last=-1,lastcur=-1e5,flag=1;
memset(cnt,0,sizeof(cnt));
for(int j=0;j<s.size();j++)
{
if(s[j]==i+'a')
lastcur=j;
else if(s[j]<i+'a'){
last=j;
cnt[s[j]-'a']++;
}
if(j-last>=m){
if(lastcur<=last){
flag=0;
break;
}
last=lastcur;
cnt[i]++;
}
}
if(flag==0)continue;
for(int ii=0;ii<26;ii++)
for(int jj=0;jj<cnt[ii];jj++)
printf("%c",ii+'a');
cout<<endl;
return 0;
}
}

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) D. Dense Subsequence 暴力的更多相关文章

  1. CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort    暴力枚举,水 1.题意:n*m的数组, ...

  2. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence

    传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...

  3. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort

    链接 题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增 思路:暴力枚举所有可能的 ...

  4. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing

    我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...

  5. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)

    http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...

  6. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)

    题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...

  7. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)

    传送门 Description You are given names of two days of the week. Please, determine whether it is possibl ...

  8. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)

    传送门 Description You are given a table consisting of n rows and m columns. Numbers in each row form a ...

  9. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B

    Description You are given a table consisting of n rows and m columns. Numbers in each row form a per ...

  10. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A

    Description You are given names of two days of the week. Please, determine whether it is possible th ...

随机推荐

  1. Mac下安装zsh(Oh My ZSH)的shell,替代原有的bash

    说明:一开始装zsh我是拒绝的,因为这个东西装简单,卸载很难,并且装了之后默认Shell的配置文件不能用了,比如~/.bashrc这些.所以在装的时候要再三考虑好! 官网:http://ohmyz.s ...

  2. 20155212 2016-2017-2 《Java程序设计》第8周学习总结

    20155212 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 Chapter14 1. Channel架构与操作 想要取得Channel的实作对象,可以使 ...

  3. (A - 整数划分 HYSBZ - 1263)(数组模拟大数乘法)

    题目链接:https://cn.vjudge.net/problem/HYSBZ-1263 题目大意:中文题目 具体思路:先进了能的拆成3,如果当前剩下的是4,就先不减去3,直接乘4,如果还剩2的话, ...

  4. 数据库优化之mysql【转】

    1. 优化流程图 mysql优化(主要增加数据库的select查询,让查询速度更快) 2. 优化mysql的方面 主要从以下四个方面去优化mysql ①存储层:如何选择一个数据库引擎,选择合适的字段列 ...

  5. %08lx

    u-boot中代码如下: debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr); 对应设备上的打印消息如下: N ...

  6. jQuery下的onChange事件在某些情况下无效

    onChage无效的原因: 虽然表面上感觉是当内容发生变化时,就会触发onchange事件,但是那只能在页面上操作.而如果通过dom对象去修改它的value则什么事也不会发生. onchange触发原 ...

  7. [转]解决阿里云mysql不能连接,配置mysql远程连接

    默认是不能用客户端远程连接的,阿里云提供的help.docx里面做了设置说明,mysql密码默认存放在/alidata/account.log 首先登录: mysql -u root -h local ...

  8. HttpClient 详解一《C#高级编程(第9版)》

    1.异步调用 Web 服务 static void Main(string[] args) { Console.WriteLine("In main before call to GetDa ...

  9. APP性能测试开始之旅

    你是不是也跟我一样在工作中存在着同样的问题,APP版本在上线后不断的会有市场人员或者用户反馈页面加载慢,进入页面loading很久(实际我们设置的加载超时是15秒,15秒内加载出内容则显示,15秒外未 ...

  10. Intellij IDEA调试功能总结

    public class Demo { public static void f1() { System.out.println("one"); System.out.printl ...