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;
}

779D. String Game 二分 水的更多相关文章

  1. CodeForces - 779D String Game 常规二分

    题意:给你两个串,S2是S1 的一个子串(可以不连续).给你一个s1字符下标的一个排列,按照这个数列删数,问你最多删到第几个时S2仍是S1 的一个子串. 题解:二分删掉的数.判定函数很好写和单调性也可 ...

  2. CodeForces - 779D String Game(二分)

    Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But i ...

  3. CodeForces 779D. String Game(二分答案)

    题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...

  4. HDU5853 Jong Hyok and String(二分 + 后缀数组)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5853 Description Jong Hyok loves strings. One da ...

  5. acdream1116 Gao the string!(hash二分 or 后缀数组)

    问题套了一个斐波那契数,归根结底就是要求对于所有后缀s[i...n-1],所有前缀在其中出现的总次数.我一开始做的时候想了好久,后来看了别人的解法才恍然大悟.对于一个后缀来说 s[i...n-1]来说 ...

  6. Codeforces Round #402 D String Game(二分)

    [题目类型]二分答案 &题解: 只要你想到二分答案就不是难题了,但我当时确实是想不到. [时间复杂度]\(O(nlogn)\) &代码: #include <cstdio> ...

  7. Codeforces 799D. String Game 二分

    D. String Game time limit per test:2 seconds memory limit per test:512 megabytes input:standard inpu ...

  8. PAT甲题题解-1050. String Subtraction (20)-水题

    #include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...

  9. Codeforces Round #402 (Div. 2) A B C sort D二分 (水)

    A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...

随机推荐

  1. 《Linux内核与分析》第五周

    20135130王川东 一.给MenuOS增加time和time-asm命令 命令:1.强制删除:rm menu -rf 2.克隆:git clone (后跟需要克隆数据所在的位置) 3.自动编译,自 ...

  2. C++ Primer Plus学习:第十一章

    运算符重载 使用方法: 在类的声明中定义重载运算符 datatype operator操作符(datatype); 定义:datatype classname:: operator操作符(dataty ...

  3. 移动平台的meta标签

    这个meta在移动平台上有非常神奇的地方. 1. <meta name="viewport" content="width=device-width; initia ...

  4. Eureka服务注册过程

    上篇博客<SpringCloud--Eureka服务注册和发现>介绍了Eureka的基本功能,这篇我们来聊聊eureka是如何实现的. 上图是eureka的架构图,Eureka分为Serv ...

  5. fsocket发送post实现异步请求

    function triggerRequest($url, $post_data = array(), $cookie = array()){ //可以通过POST或者GET传递一些参数给要触发的脚本 ...

  6. C# 开发人员的函数式编程

    摘要:作为一名 C# 开发人员,您可能已经在编写一些函数式代码而没有意识到这一点.本文将介绍一些您已经在C#中使用的函数方法,以及 C# 7 中对函数式编程的一些改进. 尽管 .NET 框架的函数式编 ...

  7. jquery截取手机号中间4位数,然后变为*

    $(function() { var phone = $('#phone').text(); var mphone = phone.substr(0, 3) + '****' + phone.subs ...

  8. 【.Net】在WinForm中选择本地文件

    相信很多朋友在日常的编程中总会遇到各钟各样的问题,关于在WinForm中选择本地文件就是很多朋友们都认为很难的一个学习.net的难点, 在WebForm中提供了FileUpload控件来供我们选择本地 ...

  9. 如何在VScode中添加代码片段

    拿 VUE 举例,新建 VUE 文件,输入前缀,出现代码段 文件 --->  首选项 ---> 用户代码片段  在输入框中输入 vue ,找到 vue.json ,然后在 vue.json ...

  10. POJ2823_Sliding Window

    以前也碰到过这种类型的题目,以前好像做出来过,但是忘记了,这次又坑了. 题目很简单,对于从前到后每一个连续的长度为k的数字,求出这段数字中的最大的数字和最小的数字. 一开始我用离散化+树状数组来更新和 ...