二分要删除几个,然后暴力判定。

#include<cstdio>
#include<cstring>
using namespace std;
int a[200010],n,m;
char s1[200010],s2[200010];
bool cant[200010];
bool check(int x)
{
memset(cant,0,sizeof(cant));
for(int i=1;i<=x;++i)
cant[a[i]]=1;
int j=1;
for(int i=1;i<=n;++i)
if((!cant[i]) && s1[i]==s2[j])
{
++j;
if(j>m)
return 1;
}
return 0;
}
int main()
{
// freopen("d.in","r",stdin);
scanf("%s%s",s1+1,s2+1);
n=strlen(s1+1);
m=strlen(s2+1);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
int l=0,r=n-1;
while(l<r)
{
int mid=((l+r+1)>>1);
if(check(mid))
l=mid;
else
r=mid-1;
}
printf("%d\n",l);
return 0;
}

【二分答案】Codeforces Round #402 (Div. 2) D. String Game的更多相关文章

  1. 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 ...

  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 ...

  3. 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 ...

  4. Codeforces Round #402 (Div. 2)

    Codeforces Round #402 (Div. 2) A. 日常沙比提 #include<iostream> #include<cstdio> #include< ...

  5. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #402 (Div. 2) 题解

    Problem A: 题目大意: 给定两个数列\(a,b\),一次操作可以交换分别\(a,b\)数列中的任意一对数.求最少的交换次数使得任意一个数都在两个序列中出现相同的次数. (\(1 \leq a ...

  9. CodeForces Round #402 (Div.2) A-E

    2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 ...

随机推荐

  1. 如何使用Navicat备份数据库脚本

    Navicat是一个实用的工具,可以用来备份数据库(Oracle.MySQL.SQLServer)脚本. 备份步骤如下: 1.打开已建立的数据库连接,鼠标右键点击,选择[转储SQL文件]->[结 ...

  2. angular的一些问题

    引入第三方类库 1.安装依赖 npm install jquey --save 2.引入项目 在angular-cli.json "scripts": [ "../nod ...

  3. Codeforces Round #478 C. Valhalla Siege

    C. Valhalla Siege time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. 【转载】惊天大悲剧-Hadoop的rmr和trash

    转自:http://java-doom.iteye.com/blog/1898000 这两天在操作Hadoop集群时,由于一个误操作,制作了一个天大的悲剧 不小心把Hadoop集群上的所有文件全部删除 ...

  5. 【LA4670-Dominating Patterns】AC自动机

    http://acm.hust.edu.cn/vjudge/problem/19224 题意:给定n个单词,一个字符串,问哪些单词在字符串中出现的次数最多.单词aba,文本ababa,则aba出现了2 ...

  6. 汕头市队赛 C SRM 05 - YYL 杯 R1 T3!

    C SRM 05 - YYL 杯 R1 背景 tjmak 描述 给一个大小为n的序列V.序列里的元素有正有负.问至少要删除多少个元素使得序列里不存在区间(要求非空)和 >= S.如果答案大于m, ...

  7. 51nod 扔盘子

    题目传送门 这道题一开始写了n方的算法 果不其然 它T了 所以就想想o(n)的算法 写不出来 就像sbzhq学习了一下 这道题啊 要维护一下从深度1到n每一段的最小值以及他的位置 然后就暴力搞一搞就o ...

  8. [POJ2406&POJ1961]用KMP解决字符串的循环问题两例

    翻阅了一下网上资料,发现大部分都说这题是找规律...或是说YY出的一个算法..不会证明... 然后就脑补了一下证明 ~ 结论:对于一个字符串S[1..N],如果N mod (N-next[N])=0 ...

  9. 【BZOJ】1579: [Usaco2009 Feb]Revamping Trails 道路升级

    [算法]分层图最短路 [题解] 考虑k层一模一样的图,然后每个夹层都在每条边的位置新加从上一层跨越到下一层的边权为0的边,这样至多选择k条边置为0. 然后考虑方便的写法. SPFA 第一次SPFA计算 ...

  10. [object-c 2.0 程序设计]object-c review (一)

    // // main.m // cmdTry // // Created by Calos Chen on 2017/8/21. // Copyright © 2017年 Calos Chen. Al ...