传送门:D Dense Subsequence

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

思路:字典序 例如 aaaaaaab < ab  也就是说,如果满足要求的取法中取到了b 那么所有的a都应该被取到,这样才可以保证字典序最小,那么也就是说在26个字母中找到一定要被取的最大字母,然后再确定最大的字母的个数,比它小的全部要取

AC代码:

 #include "stdio.h"
#include "string.h"
int main()
{
int m,k,flag,i,j,c[],now;
char s[];
while(scanf("%d",&m)!=EOF)
{
getchar();
gets(s);
memset(c,,sizeof(c));
int l=strlen(s);
for(j=+'a'; j<+'a'; j++)
{
k=;flag=;
for(i=; i<l; i++)
{
k++;
if(s[i]<=j)
{
k=;
if(s[i]==j) c[j-'a']++;
}
if(k>=m)
flag=;
}
if(flag) break;
}
k=;c[j-'a']=;now=;
for(i=; i<l; i++)
{
k++;
if(s[i]<j)
k=;
else if(s[i]==j)
now=i;
if(k==m)
{
k=;
i=now;
c[j-'a']++;
}
}
for(i=; i<=; i++)
{ //printf("%d ",c[i]);
for(j=; j<c[i]; j++)
printf("%c",i+'a');
}
printf("\n");
}
return ;
}

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) B. Batch Sort

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

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

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

  4. 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个点,求射 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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. Unity里的Mesh属性

    ----------------------------------------------------------------------------------------------- Mesh ...

  2. 搭建XMPP学习环境

    XMPP(Extensible Messaging and Presence Protocol,前称Jabber)是一种以XML为基础的开放式IM协议.xmpp被人熟知,google talk肯定有一 ...

  3. 微信"附近的人"新增商家公众号入驻功能

    微信近日升级了“附近的人”,新增商家公众号(认证的服务号和有卡券功能的公众号)可自入驻,这是微信在推出卡券和微信wifi功能后,又一加强连接线下商户能力的功能. 微信在“附近的人”中 增加搜索商户功能 ...

  4. 使用phpMyAdmin修改MySQL数据库root用户密码

    点击顶部的“SQL”标签进入sql命令输入界面.输入以下命令: update mysql.user set password=PASSWORD('snsgou$123456') where user= ...

  5. 进阶系列一【绝对干货】---SQL语句执行效率优化

    1.尽量适用联接查询来取代子查询 2.如果要用子查询,用EXISTS替代IN.用NOT EXISTS替代NOT IN,因为EXISTS引入的子查询只是测试是否存在符合子查询中指定条件的行,效率较高.无 ...

  6. HTML5CSS3特效-上下跳动的小球-遁地龙卷风

    (-1)写在前面 我用的是chrome49,这个idea是我在stackoverflow上回答问题时看到了,多谢这位同行,加深了我对很多技术点的理解,最近刚到北京,忙碌了一两天,在后续的日子里,会被安 ...

  7. java线程与缓存

    如果在你的服务中用了一些第三方的服务,最好使用缓存配合线程的方式去访问第三方的服务,以免引发线程安全问题,因为第三方的服务你不知道人家对于多线程是如何处理的,所以我们要在自己的程序中做一些线程安全的处 ...

  8. Servlet 之 GenericServlet

    我们都知道javaweb中servlet的三大组件 servlet filter listener 实现动态资源的  是可以继承  Servlet接口,或者集成GenericServlet .Http ...

  9. 我常用的grep命令

    查找包含某个字符的行并保存在文件 grep -rn 'test' ./*.sql >test.sql -r 是递归查找 -n 是显示行号 在当前目录下的.sql结尾的文件中查找包含 test 字 ...

  10. ubuntu下安装mcrypt

    sudo apt-get install libmcrypt4 php5-mcrypt 一句命令搞定