Codeforces Round #402 D String Game(二分)
【题目类型】二分答案
&题解:
只要你想到二分答案就不是难题了,但我当时确实是想不到.
【时间复杂度】\(O(nlogn)\)
&代码:
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
const int maxn= 2e5 +9;
string s,e;
int a[maxn],n,m;
bool vis[maxn];
bool ok(int mid)
{
memset(vis,0,sizeof(vis));
for(int i=0;i<mid;i++){
vis[a[i]-1]=1;
}
int j=0;
for(int i=0;i<n;i++){
if(!vis[i]&&e[j]==s[i]){
j++;
}
}
return j==m?true:false;
}
int main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// freopen("C:\\Users\\Zmy\\Desktop\\in.txt", "r", stdin);
cin>>s>>e;
n=s.size();
m=e.size();
for(int i=0;i<n;i++) cin>>a[i];
//这里的l和r是闭区间,也就是[l,r] 代表着范围,当然 如果增加一个也可以
int l=-1,r=n;
while(l<=r){
int mid=l+r>>1;
//这要注意l和r的顺序,不能写反了
if(ok(mid)) l=mid+1;
else r=mid-1;
}
cout<<r<<endl;
return 0;
}
Codeforces Round #402 D String Game(二分)的更多相关文章
- Codeforces Round #402 (Div. 2) A+B+C+D
Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...
- Codeforces Round #402 (Div. 2)
Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...
- Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到 1) [n<= m] cout<<n; 2) ...
- Codeforces Round #402 (Div. 2) D. String Game(二分答案水题)
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...
- 【二分答案】Codeforces Round #402 (Div. 2) D. String Game
二分要删除几个,然后暴力判定. #include<cstdio> #include<cstring> using namespace std; int a[200010],n, ...
- Codeforces Round #402 (Div. 2) A B C sort D二分 (水)
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #402 (Div. 2) D. String Game
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...
- Codeforces Round #402 (Div. 2) D String Game —— 二分法
D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...
- Codeforces Round #402 (Div. 2) D题 【字符串二分答案+暴力】
D. String Game Little Nastya has a hobby, she likes to remove some letters from word, to obtain anot ...
随机推荐
- class="no-js"
这是什么意思?看了外网的解释,比较明白了.(When Modernizr runs, it removes the "no-js" class and replaces it wi ...
- python面向对象:类方法
类的方法包括以下几种: 构造方法 :__init__(self,) 析构方法 :__del__(self) 类方法@classmethod.实例方法.静态方法@staticmethod 一.构造方法 ...
- iOS开发尺寸记录
https://kapeli.com/cheat_sheets/iOS_Design.docset/Contents/Resources/Documents/index https://help.ap ...
- PHP之PSR
PHP的PSR (PSR 称为PHP Standard Recommendations) PSR参考网址:http://www.php-fig.org/psr 在PHP中,有5个编码标准分类: ①.P ...
- Nginx之基本介绍(一)
这是一篇介绍Nginx基本信息和配置文件详情的文章,适合入门者,如果你想深入了解Nginx请绕道 什么是Nginx? Nginx是轻量级,高性能,跨平台的web服务器 Nginx的特点 更快 单个请求 ...
- python下载youtube视频
谷歌开源了一个新的数据集,BoundingBox,(网址在这里)这个数据集是经过人工标注的视频数据集,自然想将它尽快地运用在实际之中,那么首先需要将其下载下来:可以看到网址上给出的是csv文件,该文件 ...
- 【Python】【面试必看】Python笔试题
前言 现在面试测试岗位,一般会要求熟悉一门语言(python/java),为了考验求职者的基本功,一般会出 2 个笔试题,这些题目一般不难,主要考察基本功.要是给你一台电脑,在编辑器里面边写边调试,没 ...
- finecms如何控制调用子栏目的数量
finecms如何控制调用子栏目的数量?比如只要调用栏目id为23下的3个子栏目要怎么写?我们把num=3放后面不能实现,放在return前面就可以了,原来是顺序的问题,return只能放最后 {li ...
- ITouch在xcode下提示‘No such file or directory, at ‘/SourceCache/DVTi...'
版权声明:本文为博主原创文章,转载或又一次发表请先与我联系. https://blog.csdn.net/jonahzheng/article/details/37692733 用一个台老 ...
- 报错解决——Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
在导入tensorflow后,进行运算时,出现了报错Your CPU supports instructions that this TensorFlow binary was not compile ...