zoukankan      html  css  js  c++  java
  • 779D. String Game 二分 水

    Link

    题意: 给出两字符串$a$,$b$及一个序列,要求从前往后按照序列删掉$a$上的字符,问最少删多少使$b$串不为a的子串

    思路: 限制低,直接二分答案,即二分序列位置,不断check即可。

    /** @Date    : 2017-05-07 20:26:33
      * @FileName: 779D 二分答案.cpp
      * @Platform: Windows
      * @Author  : Lweleth (SoundEarlf@gmail.com)
      * @Link    : https://github.com/Lweleth
      * @Version : $Id$
      */
    #include <bits/stdc++.h>
    #define LL long long
    #define PII pair
    #define MP(x, y) make_pair((x),(y))
    #define fi first
    #define se second
    #define PB(x) push_back((x))
    #define MMG(x) memset((x), -1,sizeof(x))
    #define MMF(x) memset((x),0,sizeof(x))
    #define MMI(x) memset((x), INF, sizeof(x))
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e5+20;
    const double eps = 1e-8;
    
    int p[2*N];
    string a, b;
    int vis[2*N];
    
    int check(int x)
    {
    	int len = a.length();
    	for(int i = 0; i < len; i++) vis[i] = 0;
    	for(int i = 0; i < x; i++) vis[p[i] - 1] = 1;
    
    	int blen = b.length();
    	int cnt = 0;
    	for(int i = 0; i < len; i++)
    	{	
    		if(vis[i])
    			continue;
    		if(a[i] == b[cnt])
    			cnt++;
    		if(cnt == blen)
    			return 1;
    	}
    	return 0;
    }
    
    int main()
    {
    	while(cin >> a >> b)
        {
        	int r = a.length();
        	int l = 1;
        	for(int i = 0; i < r; i++)
        		scanf("%d", p + i);
        	while(l < r)
        	{
        		int mid = (l + r) >> 1;
        		//cout << l << "~" << r << "~" << check(mid) << endl;
        		if(check(mid))
        			l = mid + 1;
        		else r = mid;
        	}
        	printf("%d
    ", l - 1);
        }
        return 0;
    }
    
  • 相关阅读:
    通过C#来加载X509格式证书文件并生成RSA对象
    .NET删除字节数组中的0字节
    让.NET 4.0支持TLS1.2协议
    剖析信用卡 DCC 交易
    Python私有变量
    Python中类的定义
    SQL join中on与where区别
    Python私有函数和公开函数
    Python实现装饰模式的一段代码
    Python的sorted函数应用
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/6861395.html
Copyright © 2011-2022 走看看