【题目类型】二分答案

&题解:

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

【时间复杂度】\(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. confd template src格式和 templates 语法

    Template Resources Template resources are written in TOML and define a single template resource. Tem ...

  2. Instruments学习之Allocations

    Allocations:检测一个进程(选择自己的app)内存分配和使用情况等 我们启动Allocations后得到一个初始界面 初始界面.png 简单说一下上图的3个地方 1:这里有两个部分了,因为官 ...

  3. [daily][btrfs][mlocate][updatedb] mlocate不认识btrfs里面的文件

    这是mlocate的一个bug, 截至到目前还没有修复, 至少在redhat上没有修复. https://bugzilla.redhat.com/show_bug.cgi?id=906591 解决方法 ...

  4. iOS-Core-Animation-Advanced-Techniques/13-高效绘图 【没理解】

    #import "DrawingView.h" #import <QuartzCore/QuartzCore.h> @interface DrawingView () ...

  5. multiDex分包时指定主dex的class列表

    在gradle中我们使用了如下代码可以将指定类型分配到主dex中: afterEvaluate { tasks.matching { it.name.startsWith('dex') }.each ...

  6. sqlserver2014两台不同服务器上数据库同步

    sqlserver2014两台不同服务器上数据库同步   同步了快一个月了,哈哈,因为途中比较麻烦,第一次,遇到烦的地方就停下了,今天终于同步成功了,哈哈,下面我就来介绍一下我实现两台数据库同步的过程 ...

  7. centos所有版本下载源

    http://ftp.sjtu.edu.cn/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1511.iso http://mirrors.yun-idc.com/ ...

  8. TlistView基本使用

    //增加 procedure TForm1.Button1Click(Sender: TObject); var lsItem: TListItem; begin lsItem := ListView ...

  9. oracle sql小结(主要讲横列转换的例子)decode 以及case

    --建表 create table kecheng( id NUMBER, name VARCHAR2(20), course VARCHAR2(20), score NUMBER); --插入数据i ...

  10. 【LNMP】提示Nginx PHP “No input file specified”错误的解决办法

    原理: 任何对.php文件的请求,都简单地交给php-cgi去处理,但没有验证该php文件是否存在. PHP文件不存在,没办法返回普通的404错误,它返回 一个404,并带上一句”No input f ...