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 ...
随机推荐
- jc公共
1.前端和后端交互 var listparm = new DataParam("MyTableList", ddl.ToString()); var ridparm = new D ...
- Rodrigues Formula
https://en.wikipedia.org/wiki/Rodrigues%27_formula https://en.wikipedia.org/wiki/Rodrigues%27_rotati ...
- prometheus: celery, redis-export
https://github.com/nlighten/tomcat_exporter https://github.com/prometheus/jmx_exporter https://vexxh ...
- 彻底卸载tv
1.卸载 2.C:\Program Files (x86),找到teamviewer选项,右击删除 3.开始--输入regedit,打开注册表,找到如下路径:HKEY_LOCAL_MACHINE\SO ...
- panda核心数据结构
Series Series是一维带标签的数组,数组里可以放任意的数据(整数.浮点数.字符串.python Object)等等 创建函数: (1)s = pd.Series(data,index=ind ...
- pyqt5_eric6_Qt desinger
麦子学院视频教程day1 1.创建pushbutton 绑定信号和槽 Ui_mainWindow.py 1 from PyQt5 import QtCore, QtGui, QtWidgets cla ...
- 【SQL】SQL存储过程相关当前理解。(@temp=……)
1.下图左侧红框中的是SQL的存储过程,是程序同SQL之间互相调用的函数.——这里先作为了解不做深入研究. 比如客户通过ATM提款机取200元钱,程序中提交取200元钱操作,后续可能会进入SQL进行一 ...
- 配置svn用户及密码
配置账户及密码 格式: user=passwd 配置新的账户 [root@mysql conf]# vim passwd 创建两个账户 [root@mysql conf]# egrep -v &q ...
- 虚存管理页面置换算法 — FIFO和RUL算法模拟实现
本篇博文为追忆以前写过的算法系列第一篇(20081021) 温故知新 目的: 为了解决内存容量有限与多作业执行的冲突.运用了虚拟存储技术.能从逻辑上对内存进行扩充,达到扩充内存的效果.分页存储管理是实 ...
- 计算机网络 0.初识Internet与TCP/IP协议
互联网,即因特网,Internet.互联网是一个世界范围的计算机网络.连接了世界上无数的计算设备,这些计算设备为PC.基于Linux的工作站,serverservers等等. 这些设备依据其作用不同可 ...