codeforces 779 D. String Game(二分)
题目链接:http://codeforces.com/contest/779/problem/D
题意:给你一段操作序列,按顺序依次删掉字符串1中相应位置的字符,问你最多能按顺序删掉多少个字符,使得s2是剩下的字符构成的字符串的子列。
字符串长度为2e5每次查询的时间复杂度为n如果直接暴力那么复杂度就是n*n
如果二分一下答案的话复杂度就是n*logn再加上修改的复杂度总的复杂度是
(n+n)* logn
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
const int M = 2e5 + 10;
string p , t;
int a[M] , l , r , mid;
bool vis[M];
bool find(int pos) {
int len = t.size() , len2 = p.size();
int count = 0;
for(int i = 0 ; i < len ; i++) {
if(i <= mid) {
vis[a[i] - 1] = false;
}
else {
vis[a[i] - 1] = true;
}
}
for(int i = 0 ; i < len ; i++) {
if(vis[i]) {
if(t[i] == p[count]) {
count++;
}
}
if(count == len2)
return true;
}
return false;
}
int main() {
cin >> t >> p;
int len = t.size();
for(int i = 0 ; i < len ; i++) {
cin >> a[i];
vis[i] = true;
}
l = 0 , r = len - 1;
while(l <= r) {
mid = (l + r) >> 1;
int flag = find(mid);
if(flag) {
l = mid + 1;
}
else {
r = mid - 1;
}
}
cout << r + 1 << endl;
return 0;
}
codeforces 779 D. String Game(二分)的更多相关文章
- Codeforces 799D. String Game 二分
D. String Game time limit per test:2 seconds memory limit per test:512 megabytes input:standard inpu ...
- codeforces D. Mahmoud and Ehab and the binary string(二分)
题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...
- Codeforces Round #402 D String Game(二分)
[题目类型]二分答案 &题解: 只要你想到二分答案就不是难题了,但我当时确实是想不到. [时间复杂度]\(O(nlogn)\) &代码: #include <cstdio> ...
- Codeforces 778A:String Game(二分暴力)
http://codeforces.com/problemset/problem/778/A 题意:给出字符串s和字符串p,还有n个位置,每一个位置代表删除s串中的第i个字符,问最多可以删除多少个字符 ...
- Codeforces 862D. Mahmoud and Ehab and the binary string 【二分】(交互)
<题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的 Hamming ...
- Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)
题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...
- Codeforces 825D Suitable Replacement - 贪心 - 二分答案
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' c ...
- Codeforces 672D Robin Hood(二分好题)
D. Robin Hood time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces 645C Enduring Exodus【二分】
题目链接: http://codeforces.com/contest/645/problem/C 题意: 给定01串,将k头牛和农夫放进, 0表示可以放进,1表示不可放进,求农夫距离其牛的最大距离的 ...
随机推荐
- spring 的权限控制:security
下面我们将实现关于Spring Security3的一系列教程. 最终的目标是整合Spring Security + Spring3MVC 完成类似于SpringSide3中mini-web的功能. ...
- js页面3秒自动跳转
如何让当前页面3秒以后自动跳转到其他页面?JS页面自动跳转 想实现登陆后3秒自动跳转到某页的功能,在网上搜了一下,供以后使用 1.<script language= "javasc ...
- SWT 注意事项
一:GridData (1) 将 GridData 的 widthHint 设置为0,可以解决控件大小会随着这其默认值长度大小而改变的问题.
- 通过Powershell修改文件默认打开方式
修改原理 详情: Windows下通过注册表修改某个类型文件的默认打开方式和文件图标 脚本详情: Github:Change_default_programs.ps1 描述: 至少在Windows10 ...
- react学习(二)--元素渲染
元素用来描述你在屏幕上看到的内容: const element = <h1>Hello, world</h1>; 与浏览器的 DOM 元素不同,React 当中的元素事实上是普 ...
- Vsftp服务器配置文件详解
vsftp软件是我们常见的FTP服务器搭建软件,所有的配置都是基于vsftpd.conf这个配置文件的.vsftpd.conf里面主要包括安全配置,传输,用户还有权限等相关的选项.现在我们讲解下关于V ...
- WebService—— IDEA创建WebServices
一.File–>New–>Project 弹出这个对话框后,照下图的勾选然后点击Next,然后填写项目名和项目路径后,点击finish. 二.生成目录如下 需要注意的有HelloWorld ...
- OpenGL入门第一天:环境
本文是个人学习记录,学习建议看教程 https://learnopengl-cn.github.io/ 非常感谢原作者JoeyDeVries和各位翻译提供的优质教程 近况(牢骚 这几天教母校初中的OI ...
- 错误:MSSQLSERVER 17058
今天还原数据库的时候,在cmd命令行中输入sqlservr.exe -c -f -m出现了 Could not Open Error Log File 这个错误.网上查找了好多办法尝试了都没用.最后花 ...
- HDU 1847
题意略. 思路:又忘了dp,搜索这种暴力方法了.... #include<bits/stdc++.h> using namespace std; ; bool sg[maxn]; int ...