zoukankan      html  css  js  c++  java
  • 汕头市队赛 SRM13 T3

    这道题可以贪心 维护一个答案队列 枚举位置 每次将比当前位置大的队尾全部替代掉 记录删了多少了就好了

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<string>
    #define LL long long
    using namespace std;
    const int M=1e7+7;
    int n,k,cnt;
    char s[M],q[M];
    int main()
    {
        freopen("del.in","r",stdin);
        freopen("del.out","w",stdout);
        scanf("%s",s+1);
        n=strlen(s+1); scanf("%d",&k);
        int v=n-k;
        q[++cnt]=s[1];
        for(int i=2;i<=n;i++){
            while(cnt&&q[cnt]>s[i]&&v) cnt--,v--;
            q[++cnt]=s[i];
        }
        for(int i=1;i<=k;i++) printf("%c",q[i]); printf("
    ");
        return 0;
    }
    View Code

    当然 序列自动机比较明显 但是会慢很多

    #include<cstdio>
    #include<cstring>
    const int M=1000007;
    int n,k,c[M][26],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+1); 
        n=strlen(s+1);
        scanf("%d",&k);
        for(int i=1;i<=n;i++){
            int now=s[i]-'a'; 
            for(int j=i;j&&!c[j][now];c[j--][now]=i+1);
        }
        for(int i=n;i>=1;i--){
            for(int j=0;j<26;j++){
                int v=c[i][j];
                if(v) maxs(deep[i],deep[v]+1);
            }
        }
        int now=1;
        for(int l=k;l;l--){
            for(int j=0;j<26;j++){
                int v=c[now][j];
                if(v&&deep[v]>=l-1){
                    now=v;
                    putchar('a'+j);
                    break;
                }
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Mac普通用户修改了/etc/sudoers文件的解决办法
    python对缓存(memcached,redis)的操作
    线程、进程、协程和队列
    python作用域和多继承
    sokect编程进阶
    socket编程基础
    python面相对象进阶
    python异常处理
    configparser模块
    subprocess模块
  • 原文地址:https://www.cnblogs.com/lyzuikeai/p/7360454.html
Copyright © 2011-2022 走看看