汕头市队赛 SRM13 T3
2024-09-29 13:53:20
这道题可以贪心 维护一个答案队列 枚举位置 每次将比当前位置大的队尾全部替代掉 记录删了多少了就好了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#define LL long long
using namespace std;
const int M=1e7+;
int n,k,cnt;
char s[M],q[M];
int main()
{
freopen("del.in","r",stdin);
freopen("del.out","w",stdout);
scanf("%s",s+);
n=strlen(s+); scanf("%d",&k);
int v=n-k;
q[++cnt]=s[];
for(int i=;i<=n;i++){
while(cnt&&q[cnt]>s[i]&&v) cnt--,v--;
q[++cnt]=s[i];
}
for(int i=;i<=k;i++) printf("%c",q[i]); printf("\n");
return ;
}
当然 序列自动机比较明显 但是会慢很多
#include<cstdio>
#include<cstring>
const int M=;
int n,k,c[M][],deep[M];
char s[M];
void maxs(int& x,int y){if(x<y) x=y;}
int main(){
freopen("del.in","r",stdin);
freopen("del.out","w",stdout);
scanf("%s",s+);
n=strlen(s+);
scanf("%d",&k);
for(int i=;i<=n;i++){
int now=s[i]-'a';
for(int j=i;j&&!c[j][now];c[j--][now]=i+);
}
for(int i=n;i>=;i--){
for(int j=;j<;j++){
int v=c[i][j];
if(v) maxs(deep[i],deep[v]+);
}
}
int now=;
for(int l=k;l;l--){
for(int j=;j<;j++){
int v=c[now][j];
if(v&&deep[v]>=l-){
now=v;
putchar('a'+j);
break;
}
}
}
return ;
}
最新文章
- 【linux使用】bash shell命令行常用快捷键 (转载)
- KindEditor上传本地图片在ASP.NET MVC的配置
- HttpClient设置代理,超时,以及得到cookies
- transition的四个属性
- CODEVS 3139 栈练习3
- ASP.NET实现列表页连接查询 拼接sql语句 绑定grivdView
- 关于js封装框架类库之样式操作
- gtk+blade+anjuta 的简单实例
- docker~linux下的部署和基本命令
- Maven依赖的是本地工程还是仓库jar包?
- Gauge----自动化测试工具--使用
- python中使用redis发布订阅者模型
- 源码来袭:bind手写实现
- ADO五大对象
- SpringBoot-@PathVariable
- IntelliJ IDEA 中SpringBoot对Run/Debug Configurations配置 SpringBoot热部署
- 基于asp.net + easyui框架,一步步学习easyui-datagrid——实现分页和搜索(二)
- Redis客户端连接以及持久化数据(三)
- git clone Google的代码失败的解决方法
- MySQL学习笔记:insert into select
热门文章
- 第三课:PHP 语法
- Linux(CentOS6.5 x64)下版本安装及升级kangle+EasyPanel
- HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。
- 裸机——I2C
- [Link-Cut-Tree][BZOJ2002]弹飞绵羊
- 2037: [Sdoi2008]Sue的小球
- 3226: [Sdoi2008]校门外的区间
- 关于requestMapping 进行url映射实现小小知识点 以及如何获取请求的url中的参数
- linux 多播
- X的N次方。N比较大。