【题目类型】二分答案

&题解:

只要你想到二分答案就不是难题了,但我当时确实是想不到.

【时间复杂度】\(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(二分)的更多相关文章

  1. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  2. Codeforces Round #402 (Div. 2)

    Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...

  3. 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) ...

  4. 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 ...

  5. 【二分答案】Codeforces Round #402 (Div. 2) D. String Game

    二分要删除几个,然后暴力判定. #include<cstdio> #include<cstring> using namespace std; int a[200010],n, ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. React event

    React event 组件: React 自有方法 用户定义方法 一.虚拟事件对象 事件处理器将会传入 虚拟事件对象 的实例,一个对浏览器本地事件的跨浏览器封装.它有和浏览器本地事件相同的属性和方法 ...

  2. D. Who killed Cock Robin 湖北省大学程序设计竞赛

    链接:https://www.nowcoder.com/acm/contest/104/C来源:牛客网 The Sparrow is for trial, at next bird assizes,w ...

  3. 微信小程序image组件中aspectFill和widthfix模式应用详解

    aspectFill 与 widthfix 都是保持宽高比不变 aspectFill 保持纵横比缩放图片,只保证图片的短边能完全显示出来.也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发 ...

  4. angularjs 异步请求无法更新数据

    angularjs 有个问题就是第二次ajax请求数据再次赋值给 $scope.data,需要更新视图数据的时候,却不能更改视图数据,这个是因为angularjs的$watch不能监听到JS对$sco ...

  5. php新加扩展模块

    记录下在已经编译安装的PHP上面增加扩展模块,下面以安装mbstring.so为例 1.进入PHP源码文件中的mbstring文件夹,一般都是在ext目录 cd php-5.5.29/ext/mbst ...

  6. go install and go captcha

    https://blog.csdn.net/liuhongwei123888/article/details/8512815 [gocaptcha]     http://www.cnblogs.co ...

  7. linux 软/硬链接详解

    SYNOPSIS ln [OPTION]... [-T] TARGET LINK_NAME (1st form) ln [OPTION]... TARGET (2nd form) ln [OPTION ...

  8. [dpdk] dpdk --lcores参数

    dpdk程序的命令行参数 --lcores可以设置lcore到CPU processer的多对多映射关系. 这样既可以提供CPU processor的伸缩扩展,同时也保证了EAL thread的运行环 ...

  9. =[Mathematics] 数学主题

    https://www.douban.com/group/maths/ 圆锥体体积公式的证明

  10. Vue子组件调用父组件的方法

    Vue子组件调用父组件的方法   Vue中子组件调用父组件的方法,这里有三种方法提供参考 第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法 父组件 <temp ...