【题目类型】二分答案

&题解:

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

【时间复杂度】\(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. elasticsearch 安装配置详解

    一.安装 简单的安装与启动于前文ElasticSearch初探(一)已有讲述,这里不再重复说明. 二.启动 1.自带脚本启动 1)bin/elasticsearch,不太任何参数,默认在前端启动 2) ...

  2. php之运算符

    运算符优先级相同,运算符的结合方向决定了该如何运算, 一.运算符优先级 组合方向 运算符 附加信息 无 clone new clone和new 左 [ array 右 ** 算术运算符 右 ++ -- ...

  3. 2012年蓝桥杯省赛A组c++第1题(xy迭代增殖)

    /* 微生物增殖 题目: 假设有两种微生物 X 和 Y X出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍). 一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分 ...

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

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

  5. 半屏控制器,view: UIViewController+KNSemiModal

    半屏控制器,view:  UIViewController+KNSemiModal https://github.com/kentnguyen/KNSemiModalViewController

  6. eclipse debug模式

    eclipse debug模式 1.怎样在Eclipse中设置断点 方法/步骤 1 首先打开工程项目 2 第一种是,把鼠标移动想要设置断点的行,在行号前面空白地方双击,就会出现断点 3 第二种是,在菜 ...

  7. LeetCode 589 N-ary Tree Preorder Traversal 解题报告

    题目要求 Given an n-ary tree, return the preorder traversal of its nodes' values. 题目分析及思路 题目给出一棵N叉树,要求返回 ...

  8. winform窗体启动过程

    窗体启动执行顺序:FormShowFormPaintFormActivateFormResize 关闭窗体过程FormCloseFormDestroy 最小化再最大化:FormPaintFormRes ...

  9. Selenium功能自动化测试工具

    Selenium也是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE.Mozilla Firefox.Mozilla Suite ...

  10. 学习UDP

    参考博客:https://www.cnblogs.com/skyfsm/p/6287787.html 简单编写了 udp的小程序,udp_client 端通过终端输入字符,然后发送给udp_serve ...