Codeforces_779_D.String Game_(二分)
2 seconds
512 megabytes
standard input
standard output
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
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.
题意:给定两个字符串str1和str2,再给定一个strlen(str1)的整数序列,整数i表示从str1中删除位置处于i上的字符(即一次删除操作),删除后下标不变。问最多执行多少次删除操作,使剩下的字符串依然可以通过删除字符变成str2.
妈蛋啊,比赛时弄死没想到啊。。。注意力全放在了两个字符串上。。。结果序列才是关键啊。。。
思路:二分整数序列,然后找删除后是否合法。。。就这么简单。。。继续努力。。。
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<vector>
- #include<algorithm>
- #include<stdlib.h>
- using namespace std;
- #define N 200005
- char str1[N],str2[N];
- int num[N];
- bool del[N];
- int main()
- {
- scanf("%s%s",str1+,str2+);
- int len1=strlen(str1+),len2=strlen(str2+);
- for(int i=;i<=len1;i++)
- scanf("%d",&num[i]);
- int l=,r=len1,res=;
- while(l<=r)
- {
- int mid=(l+r)>>;
- memset(del,,sizeof(del));
- for(int i=;i<=mid;i++)
- del[num[i]]=;
- int pos=;
- for(int i=;i<=len1;i++)
- {
- if(del[i]==)
- continue;
- if(pos>len2)
- break;
- if(str1[i]==str2[pos])
- pos++;
- }
- if(pos>len2)
- {
- res=mid;
- l=mid+;
- }
- else
- r=mid-;
- }
- printf("%d\n",res);
- return ;
- }
Codeforces_779_D.String Game_(二分)的更多相关文章
- HDU5853 Jong Hyok and String(二分 + 后缀数组)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5853 Description Jong Hyok loves strings. One da ...
- acdream1116 Gao the string!(hash二分 or 后缀数组)
问题套了一个斐波那契数,归根结底就是要求对于所有后缀s[i...n-1],所有前缀在其中出现的总次数.我一开始做的时候想了好久,后来看了别人的解法才恍然大悟.对于一个后缀来说 s[i...n-1]来说 ...
- Codeforces Round #402 D String Game(二分)
[题目类型]二分答案 &题解: 只要你想到二分答案就不是难题了,但我当时确实是想不到. [时间复杂度]\(O(nlogn)\) &代码: #include <cstdio> ...
- Codeforces 799D. String Game 二分
D. String Game time limit per test:2 seconds memory limit per test:512 megabytes input:standard inpu ...
- 779D. String Game 二分 水
Link 题意: 给出两字符串$a$,$b$及一个序列,要求从前往后按照序列删掉$a$上的字符,问最少删多少使$b$串不为a的子串 思路: 限制低,直接二分答案,即二分序列位置,不断check即可. ...
- codeforces D. Mahmoud and Ehab and the binary string(二分)
题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...
- Codeforces 862D. Mahmoud and Ehab and the binary string 【二分】(交互)
<题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的 Hamming ...
- Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)
题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...
- 【CF676C】Vasya and String(二分查找,线性扫描尺取法)
题意: 给出一个长度为n的字符串,只有字符'a'和'b'.最多能改变k个字符,即把'a'变成'b'或把'b'变成'a'. 问改变后的最长连续相同字符的字串长度为多少. 首先是二分查找,好想也好写 .. ...
随机推荐
- HDOJ 5387 Clock 水+模拟
Clock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...
- mysql链接 及备份
服务器数据库命令:mysql -usparks -pi6K1yRWUQVaIR79Z5vG1 -hrm-bp13z51p96xdax6i0.mysql.rds.aliyuncs.com 服务器数据库备 ...
- union关键字及大小端模式
1. union 关键字 union 维护足够的空间来置放多个数据成员中的“一种”,而不是为每一个数据成员配置空间,在 union 中所有的数据成员共用一个空间,同一时间只能储存其中一个数据成员,所有 ...
- 【bzoj4597】 [Shoi2016]随机序列
可以发现加减号之间可以互相抵消. 真正加到答案里的只有一些前缀积. 记s[i]为a[1]*a[2]*a[3]...*a[i].那s[i]在答案中出现的次数就是2*3^(n-i-1); 修改一个数只会对 ...
- what is Servlet Container[转载]
1 在这个博客中,我将描述一下web服务器.Servlet容器的基本概念,以及Servlet容器和jvm之间的关系.我想要证明的是Servlet容器不过就是一个java程序. 2 什么是web服务器 ...
- srcset
<div id="pg-334-2" class="panel-grid panel-has-style"> <div style=" ...
- 【OI】指针线段树&指针
对于线段树,我们一般需要n*4的空间去存储线段树,然后有一种玄学操作是用指针来实现线段树. #include <inttypes.h> #include <algorithm> ...
- hdoj--1379--DNA Sorting(排序水题)
DNA Sorting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- bzoj3196 二逼平衡树——线段树套平衡树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3196 人生中第一棵树套树! 写了一个晚上,成功卡时 9000ms+ 过了! 很要注意数组的大 ...
- 【148】DevExpress相关控件使用
---------------------------------------------------------------------------------------------------- ...