Codeforces 778A:String Game(二分暴力)
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(二分暴力)的更多相关文章
- Codeforces 799D. String Game 二分
D. String Game time limit per test:2 seconds memory limit per test:512 megabytes input:standard inpu ...
- 【bzoj5085】最大 二分+暴力
题目描述 给你一个n×m的矩形,要你找一个子矩形,价值为左上角左下角右上角右下角这四个数的最小值,要你最大化矩形的价值. 输入 第一行两个数n,m,接下来n行每行m个数,用来描述矩形 n, m ≤ 1 ...
- 【BZOJ4716】假摔 二分+暴力
[BZOJ4716]假摔 Description [题目背景] 小Q最近喜欢上了一款游戏,名为<舰队connection>,在游戏中,小Q指挥强大的舰队南征北战,从而成为了一名dalao. ...
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- codeforces 650D D. Image Preview (暴力+二分+dp)
题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...
- Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...
- CodeForces - 779D String Game(二分)
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But i ...
- codeforces D. Mahmoud and Ehab and the binary string(二分)
题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...
- CodeForces 779D. String Game(二分答案)
题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
随机推荐
- Go 语言如果按这样改进,能不能火过 Java?
据 InfoWorld 消息,为改进 Go 语言的开发工具,Go 可能会获得自己的语言服务器,类似于 Microsoft 和 Red Hat 的语言服务器协议. 消息是从 Go 语言开发者的讨论组中流 ...
- XF相对布局
using System; using Xamarin.Forms; using Xamarin.Forms.Xaml; [assembly: XamlCompilation (XamlCompila ...
- WPF 元素tag属性绑定一个属性或一个对象
<Window x:Class="CollectionBinding.CategoryDataTemp" xmlns="http://schemas. ...
- XAML的命名空间 - CSDN博客
原文:XAML的命名空间 - CSDN博客 一个最简单的XAML例子 <Window x:Class="WpfApplication1.MainWindow" xmlns=& ...
- Delphi Android 将Google ZXing 整合(调用Jar文件)
前篇文章介绍了在delphi App(以下简称App)中可使用intent来调用Google ZXing 条码扫描器(以下简称zx),其各有优缺点,优点是我们不需关注zx本身的细节,只需调用其接口即可 ...
- Win8 Metro(C#)数字图像处理--3.2图像方差计算
原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...
- SEED缓冲区溢出实验笔记
缓冲区溢出实验(Linux 32位) 参考教程与材料:http://www.cis.syr.edu/~wedu/seed/Labs_12.04/Software/Buffer_Overflow/ (本 ...
- 元素命名空间中的“MvcBuildViews”无效
原文:元素命名空间中的"MvcBuildViews"无效 症状描述: VS2010打开项目时提示:"元素 命名空间"http://schemas.microso ...
- android中优雅实现recyclerview
在慕课网上看了Abner_泥阿布老师不一样的RecyclerView优雅实现复杂列表布局这个视频课程,本人在Ubuntu16.04LTS下使用android studio2.2.3按照老师讲解写的代码 ...
- 微信小程序把玩(二十)slider组件
原文:微信小程序把玩(二十)slider组件 slider滑动组件用的不太多,在其他平台反正我是用的不多 主要属性: wxml <slider max="100" step= ...