zoukankan      html  css  js  c++  java
  • 【codeforces 779D】String Game

    【题目链接】:http://codeforces.com/contest/779/problem/D

    【题意】

    给你一段操作序列;
    按顺序依次删掉字符串1中相应位置的字符;
    问你最多能按顺序删掉多少个字符;
    使得s2是剩下的字符构成的字符串的子列;

    【题解】

    二分枚举能够按顺序删掉多少个字符m;
    然后把1..m相应的字符标记成已经删掉了;
    然后O(N)判断s2是不是剩下的字符的子串;
    心态炸了.

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%lld",&x)
    
    typedef pair<int, int> pii;
    typedef pair<LL, LL> pll;
    
    const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
    const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
    const double pi = acos(-1.0);
    const int N = 2e5 + 1000;
    
    char s1[N], s2[N];
    bool bo[N];
    int a[N], n, l2;
    
    bool ok()
    {
        for (int i = 1, j = 1; i <= n && j <= l2; i++)
        {
            if (!bo[i]) continue;
            if (s1[i] == s2[j])
            {
                j++;
                if (j > l2)
                    return true;
            }
        }
        return false;
    }
    
    int main()
    {
        //freopen("F:\rush.txt", "r", stdin);
        scanf("%s", s1 + 1);
        n = strlen(s1 + 1);
        scanf("%s", s2 + 1);
        l2 = strlen(s2 + 1);
        rep1(i, 1, n)
            rei(a[i]);
        int l = 0, r = n, ans = 0;
        while (l <= r)
        {
            int m = (l + r) >> 1;
            rep1(i, 1, n)
                bo[a[i]] = true;
            rep1(i, 1, m)
                bo[a[i]] = false;
            if (ok())
            {
                ans = m;
                l = m + 1;
            }
            else
                r = m - 1;
        }
        printf("%d
    ", ans);
        return 0;
    }
  • 相关阅读:
    AD域渗透测试笔记
    ctf之WEB练习一
    CTF之crpto练习三
    ctf之WEB练习二
    ctf之WEB练习三
    [转]Ant学习笔记——自己构建Ant编译环境
    [转]【NoSQL】NoSQL入门级资料整理(CAP原理、最终一致性)
    啥叫异步调用
    C++中虚函数的作用是什么?它应该怎么用呢?
    [转]Thrift连接池实现
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626587.html
Copyright © 2011-2022 走看看