Codeforces Round #402 (Div. 2) D
Description
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a1... a|t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya"
"nastya"
"nastya"
"nastya"
"nastya"
"nastya"
"nastya".
Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.
It is guaranteed that the word p can be obtained by removing the letters from word t.
The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t.
Next line contains a permutation a1, a2, ..., a|t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ ai ≤ |t|, allai are distinct).
Print a single integer number, the maximum number of letters that Nastya can remove.
ababcba
abb
5 3 4 1 7 6 2
3
bbbabb
bb
1 6 3 4 2 5
4
In the first sample test sequence of removing made by Nastya looks like this:
"ababcba"
"ababcba"
"ababcba"
"ababcba"
Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".
So, Nastya will remove only three letters.
题意:按照数字的顺序删除第一个字符串中的字符,问能不能得到子串是第二个字符串
解法:二分,反正是按照顺序来的,一个个尝试绝对不行,使用二分降低计算次数,然后记录需要删除的字符,对第二个字符进行比较,符合要求就减少范围,不符合范围就加大范围
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream> // C++头文件,C++完全兼容C
#include <algorithm> // C++头文件,C++完全兼容C
#define fre freopen("in.txt","r",stdin) //以文件代替控制台输入,比赛时很常用,能缩短输入测试样例的时间
#define INF 0x3f3f3f3f
#define inf 1e60
using namespace std; // C++头文件,C++完全兼容C
#define N 200005 // 宏定义
#define LL long long //宏定义 LL dp[N][][]; //第一个[]表示走到第几格,第二个[]表示第几行(0 或 1),第三个[]表示已经进行了几次换道
//其实第一个[]完全可以省略,因为进行操作的都是当前路段和前1个路段
int a[N],b[N];
struct P
{
int x,y,ans;
}H[N];
int ans;
bool cmd(P a,P b)
{
return a.ans<b.ans;
}
//记录每条道的值
int vis[N];
int main()
{
string s1,s2;
cin>>s1>>s2;
for(int i=;i<s1.size();i++)
{
cin>>a[i];
}
int l=,r=s1.size()-;
while(l<=r)
{
ans=;
int mid=(l+r)/;
memset(vis,,sizeof(vis));
for(int i=;i<=mid;i++)
{
vis[a[i]-]=;
}
for(int i=;i<s1.size();i++)
{
if(vis[i]==&&s2[ans]==s1[i])
{
ans++;
}
}
if(ans==s2.size())
{
l=mid+;
}
else
{
r=mid-;
}
}
cout<<l<<endl;
return ;
}
Codeforces Round #402 (Div. 2) D的更多相关文章
- Codeforces Round #402 (Div. 2)
Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...
- 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) A,B,C,D,E
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) A B C sort D二分 (水)
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 【DFS】Codeforces Round #402 (Div. 2) B. Weird Rounding
暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=1 ...
- Codeforces Round #402 (Div. 2) 题解
Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...
- Codeforces Round #402 (Div. 2) 阵亡记
好长时间没有打Codeforces了,今天被ysf拉过去打了一场. lrd也来参(nian)加(ya)比(zhong)赛(sheng) Problem A: 我去,这不SB题吗.. 用桶统计一下每个数 ...
- CodeForces Round #402 (Div.2) A-E
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...
- Codeforces Round #402 (Div. 2) B
Description Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. ...
随机推荐
- u-boot简单学习笔记(三)——AR9331 uboot启动分析
1.最开始系统上电后 ENTRY(_start)程序入口点是 _start 由board/ap121/u-boot.lds引导 2._start: cpu/mips/start.S 是第一个源程序文 ...
- Kafka知识点汇总
整体结构 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZXJpY19zdW5haA==/font/5a6L5L2T/fontsize/400/fill/I ...
- 经常使用 Java API
经常使用Java API 一. java.io.BufferedReader类(用于从文件里读入一段字符.所属套件:java.io) 1. 构造函数BufferedReader(java.io.Fil ...
- HDU 6143 Killer Names DP+快速密
Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human apprentice ...
- Spring Boot2.0之整合Redis
需要的maven依赖 jar包,是对Jedis的封装 maven依赖: <project xmlns="http://maven.apache.org/POM/4.0.0" ...
- SpringMVC配置环境中一般用的jar包
配置SpringMVC需要把这些jar包加入lib目录下 下载地址,复制到地址栏.回车即可下载 http://files.cnblogs.com/files/QW-lzm/SpringMVC----. ...
- iOS添加弹出菜单
最近接触的项目需要实现一个弹出窗,类似于点击微信navigation bar右上角的bar button所展现的弹出窗,最终效果如下: Demo代码存放在https://github.com/LuoD ...
- 【扬中集训DAY2T2】 机智的AmyZhi
[题目链接] 点击打开链接 [算法] 据说标算是暴力? 从N-200开始搜 不过我用了搜索+一些奇怪的剪枝,也A了.... [代码] 标程 #include<bits/stdc++.h> ...
- 如何生成Android的keystore文件
步骤 1 找到本机电脑上jdk安装的目录,使用cmd命令打开命令窗口,输入cd jdk目录(替换成你的jdk的bin目录),进入到jdk的bin目录,接下来你才可以使用jdk的命令进行操作 步骤 ...
- python 使用multiprocessing需要注意的问题
我们在编写程序的时候经常喜欢这样写代码 import MySQLdb import time from multiprocessing import Process conn = MySQLdb.co ...