779D. String Game 二分 水
题意: 给出两字符串$a$,$b$及一个序列,要求从前往后按照序列删掉$a$上的字符,问最少删多少使$b$串不为a的子串
思路: 限制低,直接二分答案,即二分序列位置,不断check即可。
/** @Date : 2017-05-07 20:26:33
* @FileName: 779D 二分答案.cpp
* @Platform: Windows
* @Author : Lweleth (SoundEarlf@gmail.com)
* @Link : https://github.com/Lweleth
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; int p[2*N];
string a, b;
int vis[2*N]; int check(int x)
{
int len = a.length();
for(int i = 0; i < len; i++) vis[i] = 0;
for(int i = 0; i < x; i++) vis[p[i] - 1] = 1; int blen = b.length();
int cnt = 0;
for(int i = 0; i < len; i++)
{
if(vis[i])
continue;
if(a[i] == b[cnt])
cnt++;
if(cnt == blen)
return 1;
}
return 0;
} int main()
{
while(cin >> a >> b)
{
int r = a.length();
int l = 1;
for(int i = 0; i < r; i++)
scanf("%d", p + i);
while(l < r)
{
int mid = (l + r) >> 1;
//cout << l << "~" << r << "~" << check(mid) << endl;
if(check(mid))
l = mid + 1;
else r = mid;
}
printf("%d\n", l - 1);
}
return 0;
}
779D. String Game 二分 水的更多相关文章
- CodeForces - 779D String Game 常规二分
题意:给你两个串,S2是S1 的一个子串(可以不连续).给你一个s1字符下标的一个排列,按照这个数列删数,问你最多删到第几个时S2仍是S1 的一个子串. 题解:二分删掉的数.判定函数很好写和单调性也可 ...
- CodeForces - 779D String Game(二分)
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But i ...
- CodeForces 779D. String Game(二分答案)
题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
- 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 ...
- PAT甲题题解-1050. String Subtraction (20)-水题
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...
- 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 ...
随机推荐
- Java课程实验报告 实验四 Java网络编程及安全
北京电子科技学院(BESTI) 实 验 报 告 课程:Java程序设计 班级:1352 姓名:吕松鸿 学号:20135229 成绩: ...
- Struts2(二)
以下内容是基于导入struts2-2.3.32.jar包来讲的 1.关于StrutsPrepareAndExecuteFilter 启动StrutsPrepareAndExecuteFilter时加载 ...
- Hbase的安装和配置
1,准备好hbase的linux环境下的压缩包,这里hadoop版本为hadoop2.5.0,hbase版本为 2,解压缩这个版本,不选src的,其实两个任一都行 进入到hbase安装包目录,我这里的 ...
- PAT 甲级 1043 Is It a Binary Search Tree
https://pintia.cn/problem-sets/994805342720868352/problems/994805440976633856 A Binary Search Tree ( ...
- this.AcceptButton = button1的用法:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- word批量转pdf文件快捷方法。
最近在工作中因为要遇到大量的Word文件转化为PDF文件来实现平台的迁移.但是由于文件太多,手动很费力,想到了用代码的方式: 复制下面的代码,保存的记事本,另存为vbs文件:然后把这个vbs文件放到你 ...
- poj1655 Balancing Act求树的重心
Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any nod ...
- java中枚举型的定义以及使用
1.如何定义枚举型 public enum gender{ GEN1("男","1"), GEN2("女","0"); ...
- Fdisk 分区详解
Fdisk 分区详解 来源 http://blog.itpub.net/20674423/viewspace-722812/ 1. 通过Fdisk查看系统分区详细信息: Fdi ...
- 具体数学斯特林数-----致敬Kunth
注意这里讲的是斯特林数而非斯特林公式. 斯特林数分两类:第一类斯特林数 和 第二类斯特林数. 分别记为. 首先描述第二类斯特林数. 描述为:将一个有n件物品的集合划分成k个非空子集的方法数. 比如集合 ...