• Codeforces 1194C. From S To T


    传送门

    首先贪心, $S$ 能和 $T$ 匹配就要尽量匹配,剩下的才让 $P$ 来补

    在 $S$ 全部匹配上的情况下,看看 $P$ 是否有足够的字符即可

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    using namespace std;
    typedef long long ll;
    inline int read()
    {
        int x=0,f=1; char ch=getchar();
        while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
        while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
        return x*f;
    }
    const int N=233;
    int Q,n,m,K,cnt[N],cntt[N];
    char s[N],t[N],p[N];
    bool vis[N];
    int main()
    {
        Q=read();
        while(Q--)
        {
            scanf("%s",s+1); scanf("%s",t+1); scanf("%s",p+1);
            int n=strlen(s+1),m=strlen(t+1),K=strlen(p+1);
            if(n>m) { printf("NO
    "); continue; }
            memset(vis,0,sizeof(vis));
            for(int i=0;i<30;i++) cnt[i]=cntt[i]=0;
            for(int i=1;i<=K;i++) cnt[p[i]-'a']++;
            int l=0,p=1;
            for(int i=1;i<=m;i++)
            {
                if(t[i]!=s[p]) continue;
                vis[i]=1; p++; if(p>n) break;
            }
            if(p<=n) { printf("NO
    "); continue; }
            bool GG=0;
            for(int i=1;i<=m;i++)
                if(!vis[i])
                {
                    cntt[t[i]-'a']++;
                    if(cntt[t[i]-'a']>cnt[t[i]-'a']) GG=1;
                }
            if(GG) printf("NO
    ");
            else printf("YES
    ");
        }
        return 0;
    }
  • 相关阅读:
    swap函数的例子
    实现类似shared_ptr的引用计数
    使用new分配内存的类需要自己定义拷贝构造函数
    练习13.14 13.15 13.16
    查询单词,综合例子。
    无序容器
    关联容器操作
    关联容器概述
    文本查询程序
    shared_ptr与weak_ptr的例子
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11597764.html
Copyright © 2020-2023  润新知