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表示不可放进,求农夫距离其牛的最大距离的 ...
随机推荐
- Github上fork的项目如何merge原Git项目
问题场景 小明在Github上fork了一个大佬的项目,并clone到本地开发一段时间,再提交merge request到原Git项目,过了段时间,原作者联系小明,扔给他下面这幅截图并告知合并处理冲突 ...
- 非web下的PowerMockito单元测试
一.介绍 PowerMockito 可以用来 Mock 掉 final 方法(变量).静态方法(变量).私有方法(变量).想要使用 PowerMockito Mock掉这些内容,需要在编写的测试类上使 ...
- Docker相关地址
Docker社区版(CE)地址: https://hub.docker.com/search/?type=edition&offering=community Docker文档地址: http ...
- maven 打包并导出 lib 第三方jar
一. maven 导出lib 包 执行命令 mvn dependency:copy-dependencies -DoutputDirectory=target/lib 或者在 eclipse 中执行, ...
- Unity场景和代码合并以及UnityYAMLMerge的使用
1.首先是.gitignore的配置. # Folder config file Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ ...
- JVM系列(1)- JVM常见参数及堆内存分配
常见参数配置 基于JDK1.6 -XX:+PrintGC 每次触发GC的时候打印相关日志 -XX:+UseSerialGC 串行回收模式 -XX:+PrintGCDetails 打印更详细的GC日志 ...
- java并发编程(一)----线程基础知识
在任何的生产环境中我们都不可逃避并发这个问题,多线程作为并发问题的技术支持让我们不得不去了解.这一块知识就像一个大蛋糕一样等着我们去分享,抱着学习的心态,记录下自己对并发的认识. 1.线程的状态: 线 ...
- 消息中间件-activemq消息机制和持久化介绍(三)
前面一节简单学习了activemq的使用,我们知道activemq的使用方式非常简单有如下几个步骤: 创建连接工厂 创建连接 创建会话 创建目的地 创建生产者或消费者 生产或消费消息 关闭生产或消费者 ...
- java学习-NIO(四)Selector
这一节我们将探索选择器(selectors).选择器提供选择执行已经就绪的任务的能力,这使得多元 I/O 成为可能.就像在第一章中描述的那样,就绪选择和多元执行使得单线程能够有效率地同时管理多个 I/ ...
- Python 环境管理
Python 版本管理器:pyenv zsh 配置 # 安装 curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv ...