题意:给你两个串,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. JQuery------各种版本下载

    转载: http://www.jq22.com/jquery-info122

  2. org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'parentId' in 'class java.lang.String'

    Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ' ...

  3. 奔五的人学ios:swift竟然没有字符串包括,找个简单的解决方法

    swift关于字符串的推断中 有前导.有后缀 两个方法.竟然没有包括推断. 经过学习找了个简单的解决方法: extension String { func has(v:String)->Bool ...

  4. Oracle基本操作,Oracle修改列名,Oracle修改字段类型

    oracle基本操作,Oracle修改列名,Oracle修改字段类型 >>>>>>>>>>>>>>>>& ...

  5. iOS开发-- 字符串分割、拼接

    ---------------------字符串分割实例---------------------NSString * ptr = @"I am a man"; //将字符串整体作 ...

  6. Perl socket编程

    In this article, let us discuss how to write Perl socket programming using the inbuilt socket module ...

  7. springboot 集成elasticsearch

    In this article, we will discuss about “How to create a Spring Boot + Spring Data + Elasticsearch Ex ...

  8. react设置多个className

    在一个元素上设置样式,有一个固定的样式,然后还有一个使用三元运算符根据条件添加的样式. 比如说有一个固定样式"title": <div className="tit ...

  9. 【转】java文件操作大全

    一.获得控制台用户输入的信息 public String getInputMessage() throws IOException...{         System.out.println(&qu ...

  10. JS使用中碰到的一些问题

    settimeout: 1.setTimeout(function () {//这个则会在1秒后进行弹出1 alert(1); }, 1000); 2.setTimeout(alert(1), 100 ...