CF778A(round 402 div.2 D) String Game
题意:
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|, all ai 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
思路:
二分。
实现:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std; int a[], n, m;
string s, p; bool check(int x)
{
string tmp = s;
for (int i = ; i < x; i++)
{
tmp[a[i] - ] = '*';
}
int i = , j = ;
while (i < n && j < m)
{
if (tmp[i] != p[j])
i++;
else
{
i++;
j++;
}
}
return j == m;
} int search()
{
int l = , r = n - , m;
int res = ;
while (l <= r)
{
m = (l + r) >> ;
if (check(m))
{
res = m;
l = m + ;
}
else
{
r = m - ;
}
}
return res;
} int main()
{
cin >> s >> p;
n = s.length();
m = p.length();
for (int i = ; i < n; i++)
{
scanf("%d", &a[i]);
}
cout << search() << endl;
return ;
}
CF778A(round 402 div.2 D) String Game的更多相关文章
- 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 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+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< ...
- BestCoder Round #81 (div.2) 1004 String(动态规划)
题目链接:BestCoder Round #81 (div.2) 1003 String 题意 中文题,上有链接.就不贴了. 思路 枚举起点i,计算能够达到k个不同字母的最小下标j,则此时有子串len ...
- 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) A B C sort D二分 (水)
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input stan ...
随机推荐
- DataSnap的如果网络断线,如何恢复?
timer代码很简单:var adbsevertime :TDateTime;begin try adbsevertime := ClientModule1.ServerMethods1Client. ...
- vscode——配置终端集成bash和cmd
前言 配置后bash和cmd是集成的,输入bash回车则进入bash,输入cmd回车则进入cmd 步骤 首先肯定是需要打开我们的vscode咯~ 进入终端设置 配置shell路径 根据自己的系统来复制 ...
- JQuery操作TABLE,及console.info问题。
还用alert 吗?看看console.info吧,代码的测试平台:ie9, firefox12 1. [代码][JavaScript]代码<!DOCTYPE html><html ...
- FPU同步(翻译)
本篇翻译的原英文在:http://mauve.mizuumi.net/2013/06/16/desyncs-and-fpu-synchronization/#more-725(可能要FQ) 如果你曾经 ...
- iOS沙盒(sandbox)机制及获取沙盒路径
一. 每个iOS应用SDK都被限制在“沙盒”中,“沙盒”相当于一个加了仅主人可见权限的文件夹,苹果对沙盒有以下几条限制. (1)应用程序可以在自己的沙盒里运作,但是不能访问任何其他应用程序的沙盒. ( ...
- CF838D Airplane Arrangement
题目描述:https://www.luogu.org/problemnew/show/CF838D(有翻译) (为什么博客园把我刚写的给吞了……orz) 这题当初看的十分懵逼,不过听了肖大佬的做法还是 ...
- codeforces round 420 div2 补题 CF 821 A-E
A Okabe and Future Gadget Laboratory 暴力 #include<bits/stdc++.h> using namespace std; typedef l ...
- CTR预估经典模型总结
计算广告领域中数据特点: 1 正负样本不平衡 2 大量id类特征,高维,多领域(一个类别型特征就是一个field,比如上面的Weekday.Gender.City这是三个field),稀疏 ...
- Android菜单代码
前言: 学习android断断续续也有一年半左右,但一直在学习,很少回顾以往的知识.所以我打算用业余时间来写一些这样总结性的文章,希望温故知新. 以下只是我个人的一些感悟和见解(当然会查证资料验证), ...
- OpenCV视频的读写
实验室的项目是处理视频,所以就从视频的读取和写入开始吧! 常用的接口有C++和Python,Python肯定要简洁许多,不过因为项目需要,还是用C++了(PS:其实是我被Python的速度惊到了... ...