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次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
随机推荐
- 【转】CefSharp 与 js 相互调用
转自CSDN博客博主ghui,虽然博主说要经过他同意才能转,我只是做笔记用,没做他用,所以请博主理解,在此感谢博主! 一. CefSharp调用 js CefSharp.WinForms.Chromi ...
- CefSharp For WPF响应页面点击事件
初始化 <!--浏览器--> <cefSharpWPF:ChromiumWebBrowser Name="webBrowser" Grid.Row="0 ...
- WPF 寻找控件模板中的元素
<Window x:Class="Wpf180706.Window10" xmlns="http://schemas.microsoft.com/wi ...
- MVC 调试路由
1.添加引用RouteDebug.dll 2 修改Global.asax,切记调试过后要删掉 using System;using System.Collections.Generic;using S ...
- 绕过010Editor网络验证(用python做一个仿真http server真容易,就几行代码)
010Editor是一款非常强大的十六进制编辑器,尤其是它的模板功能在分析文件格式时相当好用!网上现在也有不少010Editor的破解版,如果没钱或者舍不得花钱买授权的话,去官方下载安装包再使用注册机 ...
- Ionic2开发环境搭建-VS 2017
原文:Ionic2开发环境搭建-VS 2017 目前在VS 2017中创建Ionic2版本项目 注:在VS中开发Ionic项目,使用的Ionic(v2.x),Cordova(v6.3.1),Angul ...
- fileapi.h里的API函数(包括LockFileEx和FindFirstChangeNotification函数)
/** * This file is part of the mingw-w64 runtime package. * No warranty is given; refer to the file ...
- Qt程序发行Linux版,软件打包知识(patchelf 工具修改依赖库,确认 qmake -v 是自己使用的Qt版本,否则用export PATH进行修改)good
patchelf 工具可以修改已编译运行程序的依赖库位置和指定库链接器 patchelf --set-rpath patchelf --set-interpreter 通过这个工具 https://g ...
- Android自定义View入门(一)
最近在写一个关于音乐播放的应用,写到播放界面UI时,就想自己实现的一个播放界面.那么如何实现自定义View呢?通过查看他人博客和Android官方开发文档,初步了解了一些浅显的内容.在此记录,已供需要 ...
- C#整数类型
C#支持9种整数类型,sbyte,byte,short,ushort,int,uint,long,ulong和char. 类型 含义 ...