zoukankan      html  css  js  c++  java
  • codeforces 1231E Middle-Out

    //思路:因为可以任意位置的字符移动到首或尾位
    //所以只需每次枚举最大不需要移动的子串就好了
    #include<bits/stdc++.h>
    #define inf (0x3f3f3f3f)
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(false);    cin.tie(0),cout.tie(0);
        int q,n;    cin>>q;
        while(q--)
        {
            cin>>n;
            string stra,strb;
            cin>>stra>>strb;
            int ans = inf;
            int cur;
            for(int i=0;i!=n;++i)
            {
                cur = i;//strb的当前位置
                for(int j=0;j!=n;++j)
                {
                    if(cur!=n&&strb[cur]==stra[j])
                        ++cur;
                }
                ans = min(ans,n - cur + i);
            }
            sort(stra.begin(),stra.end());
            sort(strb.begin(),strb.end());
            if(stra != strb)
            {
                cout<<-1<<' ';
                continue;
            }
            cout<<ans<<' ';
        }
    }
    不怕万人阻挡,只怕自己投降。
  • 相关阅读:
    抉择
    PHP glob() 函数
    PHP之关闭网页错误提示
    PHP htmlentities() 函数
    PHP mysql_real_escape_string() 函数
    LFI & RFI & PHP封装协议之安全问题研究
    数据公钥加密和认证中的私钥公钥
    RSA算法
    APT攻防对抗
    安全参考
  • 原文地址:https://www.cnblogs.com/newstartCY/p/11619954.html
Copyright © 2011-2022 走看看