题意:给你两个串,S2是S1 的一个子串(可以不连续).给你一个s1字符下标的一个排列,按照这个数列删数,问你最多删到第几个时S2仍是S1 的一个子串。

题解:二分删掉的数。判定函数很好写和单调性也可以维持。 不知道为啥答案要-1.。貌似l最终指向删掉以后不再保持性质的第一个数。

#define  _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
char s1[maxn],s2[maxn];
int del[maxn];
int a[maxn];
int main() {
scanf("%s", s1);
scanf("%s", s2);
int len = strlen(s1);
int len2 = strlen(s2);
for (int i = ; i < len; i++)
scanf("%d", &a[i]);
int l = , r = len-;//二分删掉的数
while (l <= r) {
memset(del, -, sizeof(del));
int mid = l + r >> ;
int ok = ;
for (int i = ; i < mid; i++) del[a[i]-] = ;
int i = ,j = ;
while (i < len&&j < len2)
{
if (del[i] == ) { i++; continue; }
if (s1[i] == s2[j])i++, j++;
else i++;
if (j == len2)break;
}
if (j == len2) {l = mid + ; }
else r = mid- ;
}
cout << l-; }

CodeForces - 779D String Game 常规二分的更多相关文章

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

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

  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

    time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standa ...

  4. Codeforces Round #402 (Div. 2) D. String Game(二分答案水题)

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

  5. Codeforces 799D. String Game 二分

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

  6. 779D. String Game 二分 水

    Link 题意: 给出两字符串$a$,$b$及一个序列,要求从前往后按照序列删掉$a$上的字符,问最少删多少使$b$串不为a的子串 思路: 限制低,直接二分答案,即二分序列位置,不断check即可. ...

  7. codeforces 779 D. String Game(二分)

    题目链接:http://codeforces.com/contest/779/problem/D 题意:给你一段操作序列,按顺序依次删掉字符串1中相应位置的字符,问你最多能按顺序删掉多少个字符,使得s ...

  8. 【codeforces 779D】String Game

    [题目链接]:http://codeforces.com/contest/779/problem/D [题意] 给你一段操作序列; 按顺序依次删掉字符串1中相应位置的字符; 问你最多能按顺序删掉多少个 ...

  9. Codeforces 778A:String Game(二分暴力)

    http://codeforces.com/problemset/problem/778/A 题意:给出字符串s和字符串p,还有n个位置,每一个位置代表删除s串中的第i个字符,问最多可以删除多少个字符 ...

随机推荐

  1. ASP正则匹配方法

    方法二:找到匹配的进行替换 ip="127.0.0.1" Function ReplaceTest(str,patrn, replStr) Dim regEx, str1 Set ...

  2. Nginx 访问控制

    根据 IP 限制访问: location /admin/ { allow 192.168.1.1; allow 192.168.1.2; deny all; } 根据正则限制访问: location ...

  3. iOS 在已有项目添加CoreData

    本文转载至 http://cnbin.github.io/blog/2016/03/11/ios-zai-yi-you-xiang-mu-tian-jia-coredata/ 如果是新项目很好说,新建 ...

  4. URI跳转方式地图导航的代码实践

    本文转载至 http://adad184.com/2015/08/11/practice-in-mapview-navigation-with-URI/ 前言 之前介绍了我正在做的是一款定位主打的应用 ...

  5. 使用dom4j解析xml为json对象

    import java.util.List; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j. ...

  6. Django restframwork教程之类视图(class-based views)

    我们也可以使用类的views写我们的API,我们将看到这是一个强大的模式,允许我们重用公共功能,让我们的代码整洁 使用Class-based Views重新改写我们的API 打开views.py文件, ...

  7. <转>Python OOP(1):从基础开始

    转自  http://www.cnblogs.com/BeginMan/p/3510786.html 本文旨在Python复习和总结: 1.如何创建类和实例? # 创建类 class ClassNam ...

  8. 小程序判断是否授权源码 auth.js

    一.auth.js const configGlobal = require('../config/config_global.js'); var util = require('function.j ...

  9. datatable 使用LAMBDA表达查询,过滤

    DataTable dt = new DataTable(); DataColumn dc = new DataColumn("UserName", System.Type.Get ...

  10. eclipse中改变默认的workspace的方法

    1.File-->Switch Workspace-->Other 2.Window-->Preferences-->General-->Startup and Shui ...