Codeforces - 1194C - From S To T - 排序

Posted yinku

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces - 1194C - From S To T - 排序相关的知识,希望对你有一定的参考价值。

https://codeforces.com/contest/1194/problem/C
好像没什么好说的,要能构造s必须是t的子序列,并且相差的字符集合d是p的子集。
求两遍子序列就可以了,甚至不需要sort,假如用桶排的话就是O(qn)的。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
char s[105];
char t[105];
char p[105];
char d[105];

bool is_sub1(char *s, char *t) 
    int i = 0, j = 0, dt = 0;
    int sl = strlen(s);
    int st = strlen(t);
    for(; i < sl; i++) 
        while(j < st) 
            if(t[j] != s[i]) 
                d[dt++] = t[j];
                j++;
                if(j == st) 
                    return false;
                
             else 
                j++;
                break;
            
        
    
    if(i == sl) 
        while(j < st) 
            d[dt++] = t[j];
            j++;
        
        sort(d, d + dt);
        sort(p, p + strlen(p));
        d[dt] = '\0';
        //cout << d << endl;
        //cout << p << endl;
        return true;
     else 
        return false;
    


bool is_sub2(char *s, char *t) 
    int i = 0, j = 0;
    int sl = strlen(s);
    int st = strlen(t);
    for(; i < sl; i++) 
        while(j < st) 
            if(t[j] != s[i]) 
                j++;
                if(j == st) 
                    return false;
                
             else 
                j++;
                break;
            
        
    
    if(i == sl) 
        return true;
     else 
        return false;
    


int main() 
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
    //freopen("Yinku.out", "w", stdout);
#endif // Yinku
    while(~scanf("%d", &n)) 
        while(n--) 
            scanf("%s%s%s", s, t, p);
            if(is_sub1(s, t) && is_sub2(d, p)) 
                puts("YES");
             else 
                puts("NO");
            
        
    

以上是关于Codeforces - 1194C - From S To T - 排序的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 264A. Escape from Stones

G - Plus from Picture CodeForces - 1182B

Reachability from the Capital CodeForces - 999E (强连通)

Codeforces Round #162 (Div. 1) A. Escape from Stones

Make k Equal from Codeforces Round #629 (Div. 3)

Codeforces 1188E Problem from Red Panda (计数)