首页 > 其他分享 >4-1898E - Sofia and Strings

4-1898E - Sofia and Strings

时间:2023-11-20 20:24:34浏览次数:27  
标签:typedef int 字母 Sofia cin long 1898E solve Strings

题意:
题解:对于有排序操作且不限次数,最好考虑每次只对两个排序,如果t中的字母在s中的j位置,则s[0,j]之间小于t中字母的字母都要消去,用队列存s中字母的位置,扫描t,每次用s中剩余位置最小的,在消去不可用的即可。
代码:

点击查看代码
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> pll;
typedef tuple<int,int,int> TP;
const int N = 1e6 + 10;

void solve()
{
    int n,m;
    string s,t;
    cin>>n>>m;
    cin>>s>>t;
    queue<int> q[30];
    for(int i=0;i<n;i++)
    {
        int w=s[i]-'a';
        q[w].push(i);
    }
    
    for(int i=0;i<m;i++)
    {
        int w=t[i]-'a';
        if(q[w].empty()) 
        {
            cout<<"NO\n";
            return ;
        }
        int d=q[w].front();
        q[w].pop();
      //  cout<<d<<" "<<" "<<w<<" "<<t[i]<<"\n";
        for(int j=0;j<w;j++)
        {
            while(q[j].size()&&q[j].front()<d)
            {
                q[j].pop();
            }
        }
    }
    cout<<"YES\n";
}
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0 ^ 0;
}

标签:typedef,int,字母,Sofia,cin,long,1898E,solve,Strings
From: https://www.cnblogs.com/xxj112/p/17844752.html

相关文章

  • 无涯教程-D语言 - 字符串(Strings)
    字符数组我们可以用以下两种形式来表示字符数组.第一种形式直接提供大小,第二种形式使用dup方法创建字符串"Goodmorning"。char[9]greeting1="Hellolearnfk";char[]greeting2="Goodmorning".dup;这是使用上述简单字符数组形式的简单示例。importstd.stdio;voidm......
  • Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated, T-shirts + prizes!) B. Kuroni an
    Problem-1305B-Codeforces 啦啦啦,这题题目有点长,概括一下就是,希望将所有()匹配的括号去掉问你需要操作多少次 双指针,一个i一个j,从前往后记录匹配的括号如果发现:1.括号匹配2.i<jok,就放入ans (⊙o⊙)…,最后记得sort一遍ans,第一遍因为这个wa了一发 #include......
  • Strings of Impurity
    link不懂为什么都写平衡树,明明set就好了啊,思路跟平衡树差不多,实现起来较为简单。intn,m,k;ints[N];strings1,s2;intcnt[N];vector<int>t;set<int>p[N];intmain(){ios::sync_with_stdio(false);cin.tie(nullptr); cin>>s1>>s2; n=s1.size()......
  • linux 中 strings命令
     001、linux中strings命令主要是在对象文件或者二进制文件中查找可打印的字符串。 002、举例(base)[b20223040323@admin1~]$strings/bin/ls|head/lib64/ld-linux-x86-64.so.2libselinux.so.1__gmon_start___initfgetfileconfreeconlgetfilecon_finilibc......
  • CF1889A. Qingshan Loves Strings 2
    不妨考虑什么时候会无解!显然当原序列\(0,1\)数量不同,或者序列总长为奇数时会无解!否则我们设\(l=1,r=n\)!开始回文配对!如果配上了就直接删掉!并把左右端点向内移动!如果两者都是\(0\),就在末尾加上\(01\)!都是\(1\)就加最前面!以在末尾加入举例!此时如果开头是\(01\)就会多......
  • C++常用语法知识-- std::istringstream
    C++常用语法知识--std::istringstream介绍std::istringstream是C++标准库中的一个类,它用于从字符串中提取数据,并将数据转换为不同的数据类型。通常从字符串中解析数据,例如整数、浮点数等。使用方法创建std::istringstream对象,首先,需要创建一个std::istringstream对象,将......
  • [924] f-strings in Python
    ref:f-stringsinPythonref:Python'sF-StringforStringInterpolationandFormattingF-strings,alsoknownasformattedstringliterals,areafeatureintroducedinPython3.6thatprovideaconciseandconvenientwaytoembedexpressionsinside......
  • std::istringstream的用法
    1.概要std::istringstream是C++标准库中的一个类,它用于从字符串中提取数据,并将数据转换为不同的数据类型。它通常用于从字符串中解析数据,例如整数、浮点数等。以下是关于std::istringstream的详细用法:创建std::istringstream对象:首先,你需要创建一个std::istringstrea......
  • Educational Codeforces Round 154 (Rated for Div. 2) B. Two Binary Strings
    给定两个长度相等的\(01\)字符串\(a\)和\(b\)。每个字符串都是以\(0\)开始以\(1\)结束。在一步操作中,你可以选择任意一个字符串:选择任意两个位置\(l,r\)满足\(s_l=s_r\),然后让\(\foralli\in[l,r],s_i=s_l\)。询问经过若干次操作后能否使得\(a=b......
  • CF938F Erasing Substrings 题解
    ErasingSubstrings一个神奇的想法是设\(f_{i,j}\)表示在位置\([1,i]\)中,我们删去了长度为\(2^k(k\inj)\)的一些串,所能得到的最小字典序。使用二分加哈希可以做到\(O(n^2\log^2n)\),无法承受。发现对于状态\(f_{i,j}\),它已经确定了\(i-j\)位的串,因为所有\(\inj\)......