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\n", l - 1);
    }
    return 0;
}
posted @ 2017-05-16 14:58  Lweleth  阅读(276)  评论(0编辑  收藏  举报