【题目链接】:http://codeforces.com/contest/779/problem/D

【题意】



给你一段操作序列;

按顺序依次删掉字符串1中相应位置的字符;

问你最多能按顺序删掉多少个字符;

使得s2是剩下的字符构成的字符串的子列;

【题解】



二分枚举能够按顺序删掉多少个字符m;

然后把1..m相应的字符标记成已经删掉了;

然后O(N)判断s2是不是剩下的字符的子串;

心态炸了.



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 2e5 + 1000; char s1[N], s2[N];
bool bo[N];
int a[N], n, l2; bool ok()
{
for (int i = 1, j = 1; i <= n && j <= l2; i++)
{
if (!bo[i]) continue;
if (s1[i] == s2[j])
{
j++;
if (j > l2)
return true;
}
}
return false;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%s", s1 + 1);
n = strlen(s1 + 1);
scanf("%s", s2 + 1);
l2 = strlen(s2 + 1);
rep1(i, 1, n)
rei(a[i]);
int l = 0, r = n, ans = 0;
while (l <= r)
{
int m = (l + r) >> 1;
rep1(i, 1, n)
bo[a[i]] = true;
rep1(i, 1, m)
bo[a[i]] = false;
if (ok())
{
ans = m;
l = m + 1;
}
else
r = m - 1;
}
printf("%d\n", ans);
return 0;
}

【codeforces 779D】String Game的更多相关文章

  1. 【Codeforces 710F】String Set Queries

    Codeforces 710 F 思路:KMP学的还是不过关啊... 按照字符串的长度分类,如果长度大于\(\sqrt{n}\)的就扔到什么地方等待查询,否则就扔进trie里面. 对于查询,我们先在t ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  4. 【codeforces 797C】Minimal string

    [题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...

  5. 【codeforces 801B】Valued Keys

    [题目链接]:http://codeforces.com/contest/801/problem/B [题意] 定义一个对两个字符串x,y的f(x,y)函数; 返回的是一个字符串; 这个返回的字符串的 ...

  6. 【codeforces 801A】Vicious Keyboard

    [题目链接]:http://codeforces.com/contest/801/problem/A [题意] 一个字符串只由VK组成; 让你修改一个字符; 使得剩下的字符串里面子串VK的个数最大; ...

  7. 【codeforces 510C】Fox And Names

    [题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...

  8. 【codeforces 514A】Chewbaсca and Number

    [题目链接]:http://codeforces.com/contest/514/problem/A [题意] 允许你把每个数字翻转 ->x变成9-x 然后问你能够变成的最小的数字是什么; 不能 ...

  9. 【codeforces 514C】Watto and Mechanism(字典树做法)

    [题目链接]:http://codeforces.com/contest/514/problem/C [题意] 给你n个字符串; 然后给你m个询问;->m个字符串 对于每一个询问字符串 你需要在 ...

随机推荐

  1. 前台Ajax发送数据给后台

    前台发ajax请求给后台 前台代码 let data= [{receiveAdd:receiveAddVal, sendAdd:sendAddVal,distance:distance,goodsNa ...

  2. 【LeetCode-面试算法经典-Java实现】【199-Binary Tree Right Side View(从右边看二叉树)】

    [199-Binary Tree Right Side View(从右边看二叉树] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 代码下载[https://github.co ...

  3. NHibernate3剖析:Mapping篇之集合映射基础(2):Bag映射

    系列引入 NHibernate3.0剖析系列分别从Configuration篇.Mapping篇.Query篇.Session策略篇.应用篇等方面全面揭示NHibernate3.0新特性和应用及其各种 ...

  4. HTML 5 中FileReader的使用

    FileReader 接口主要用来把文件读入到内存中,而且读取文件里的数据.FileReader接口提供了一个异步API,使用该API能够在浏览器主线程中异步訪问文件系统 ,读取文件里的数据. Fil ...

  5. 在 Swift 项目中实现侧滑菜单-利用 SWRevealViewController

    你可以完全自己手动写一个侧滑菜单,但是现在在 GitHub 上面已经有很多免费的开源库了,如果不是有很特别的需求,大可不必新建一个轮子. 在这里我使用的这个第三方库名字叫做 SWRevealViewC ...

  6. HDU 1214 圆桌会议 圆环逆序

    http://acm.hdu.edu.cn/showproblem.php?pid=1214 题目大意: 一群人围着桌子座,如果在一分钟内一对相邻的人交换位置,问多少分钟后才能得到与原始状态相反的座位 ...

  7. zynq修改ramdisk文件系统

    ⑴ 挂载 Ramdisk新建目录 tmp, 并将 uramdisk.image.gz 拷贝至该目录$ cd <WORKDIR>/Filesystem$ mkdir tmp$ cp uram ...

  8. 新浪sae上安装原生wordpress4.1

    1. 加入/改动wp-config.php文件 <?php /** * WordPress 基础配置文件. * * 本文件包括下面配置选项: MySQL 设置.数据库表名前缀. * 密匙.Wor ...

  9. [Nuxt] Navigate with nuxt-link and Customize isClient Behavior in Nuxt and Vue.js

    Because Nuxt renders pages on the server, you should use the nuxt-link components to navigate betwee ...

  10. [RxJS] RefCount: automatically starting and stopping an execution

    With the connect() method on a ConnectableObservable, the programmer is responsible for avoiding lea ...