http://codeforces.com/problemset/problem/778/A

题意:给出字符串s和字符串p,还有n个位置,每一个位置代表删除s串中的第i个字符,问最多可以删除多少个字符使得s串依旧包含p串。

思路:想到二分,以为二分做法依旧很暴力。但是别人的做法确实就是二分暴力搞啊。

枚举删除字符数,然后判断的时候如果s串包含p串,那么可以往右区间找,否则左区间找。

 #include <bits/stdc++.h>
using namespace std;
#define N 200010
char s[N], p[N];
int id[N], vis[N], n, m; bool check(int x) {
memset(vis, , sizeof(vis));
for(int i = ; i <= x; i++) vis[id[i]] = ;
for(int i = , cnt = ; i <= n; i++) {
if(vis[i]) continue;
if(p[cnt] == s[i]) cnt++;
if(cnt == m + ) return true;
}
return false;
} int main() {
scanf("%s %s", s + , p + );
n = strlen(s + ), m = strlen(p + );
for(int i = ; i <= n; i++) scanf("%d", &id[i]);
int l = , r = n, ans = ;
while(l <= r) {
int mid = (l + r) >> ;
if(check(mid)) {
ans = mid; l = mid + ;
} else r = mid - ;
}
printf("%d\n", ans);
return ;
}

Codeforces 778A:String Game(二分暴力)的更多相关文章

  1. Codeforces 799D. String Game 二分

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

  2. 【bzoj5085】最大 二分+暴力

    题目描述 给你一个n×m的矩形,要你找一个子矩形,价值为左上角左下角右上角右下角这四个数的最小值,要你最大化矩形的价值. 输入 第一行两个数n,m,接下来n行每行m个数,用来描述矩形 n, m ≤ 1 ...

  3. 【BZOJ4716】假摔 二分+暴力

    [BZOJ4716]假摔 Description [题目背景] 小Q最近喜欢上了一款游戏,名为<舰队connection>,在游戏中,小Q指挥强大的舰队南征北战,从而成为了一名dalao. ...

  4. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  5. codeforces 650D D. Image Preview (暴力+二分+dp)

    题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...

  6. Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力

    Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...

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

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

  8. codeforces D. Mahmoud and Ehab and the binary string(二分)

    题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...

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

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

随机推荐

  1. springmvc 与 springfox-swagger2整合

    一.pom.xml引入基于maven的swagger依赖 <dependency> <groupId>io.springfox</groupId> <arti ...

  2. Eclipseproject标准的文件夹层次

    为什么特别写一个文档首场讲座解释什么层次,你是eclipse正在使用java.io.File类在读workspace档,我相信不知道eclipse,为了避免以后再出现这样的令人难堪的情况,还是编写这样 ...

  3. XF警告试图

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. String 源码分析

    Java 源码阅读 - String String 类型看起来简单,实际上背后的复杂性基本可以涵盖了整个 Java 设计,涉及到设计模式(不可变对象).缓存(String Pool 的理念).JVM( ...

  5. WPF Dispatcher的使用

     <Window x:Class="DispatcherExam.MainWindow"         xmlns="http://schemas.micro ...

  6. wcf服务端代码方式及客户端代码方式

    ServiceHost  host;  // 全局 host = new ServiceHost(typeof(实现服务接口的类)); host.open(); 用代码配置端点的方法 host.add ...

  7. C# 获取当前月份天数的三种方法总结

    方法一: //最有含量的一种 int days = System.Threading.Thread.CurrentThread.CurrentUICulture.Calendar.GetDaysInM ...

  8. uwp开发————换背景图片

    原文:uwp开发----换背景图片 用后台代码来实现对容器背景的切换,用本地图片作为背景. 把需要的图片素材放到Assets文件夹下 前台xaml代码如下: <Grid x:Name=" ...

  9. 获取UWP配置文件中的版本信息

    原文:获取UWP配置文件中的版本信息 在一般的软件中,我们都会显示当前软件的版本信息.以前作者都是在发版的时候修改一下UWP的配置文件中的版本信息和软件中的版本信息.但是每次这样很麻烦,有时间忘记修改 ...

  10. LLVM和GCC的区别(LLVM提供了模块化的编译模块,非常有利于重用,以前的编译器都没有做到这一点)

    最近在Mac OS X Mountain Lion下用Xcode进行开发,发现在编译选项里有如下所示的这两种编译器:一个是Apple LLVM compiler 4.2,另外一个是LLVM GCC 4 ...