cf.VK CUP 2015.C.Name Quest(贪心)
2 seconds
256 megabytes
standard input
standard output
A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy. For example, if s=«aba», then strings «baobab», «aabbaa», «helloabahello» make him very happy and strings «aab», «baaa» and «helloabhello» do not.
However rather than being happy once, he loves twice as much being happy twice! So, when he got string t as a present, he wanted to cut it in two parts (the left part and the right part) so that each part made him happy.
Help s determine the number of distinct ways to cut the given string t into two parts in the required manner.
The first line contains string s, consisting of lowercase English letters. The length of string s is from 1 to 1000 letters.
The second line contains string t, that also consists of lowercase English letters. The length of string t is from 1 to 106 letters.
Print the sought number of ways to cut string t in two so that each part made s happy.
aba baobababbah
2
mars sunvenusearthmarsjupitersaturnuranusneptune
0
先从左到右,找到子串中的第一个母串,让l = sub[index];(对应母串的最后一个字母)
再从右往左找第一个符合的母串,让r = sub[index] ;(对应母串的第一个字母)
最后printf ("%d\n" , max (0 , r - l))
然后我把代码写搓了 , orz
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
string p , s ; int main ()
{
//freopen ("a.txt" , "r" , stdin ) ;
cin >> p ;
cin >> s ;
int l = , r = s.size () - ;
for (int i = ; i < p.size() ; i++) {
while (l < s.size () && p[i] != s[l]) {
l ++ ;
}
if (l < s.size ()) {
l ++ ;
}
else {
puts ("") ;
return ;
}
}
for (int i = p.size () - ; i >= ; i--) {
while (r >= && p[i] != s[r]) {
r-- ;
}
if (r >= ) {
r-- ;
}
else {
puts ("") ;
return ;
}
}
l -- , r++ ;
printf ("%d\n" , max ( , r - l) ) ;
}
cf.VK CUP 2015.C.Name Quest(贪心)的更多相关文章
- cf.VK CUP 2015.B.Mean Requests
Mean Requests time limit per test 4 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...
- Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) E 贪心
http://codeforces.com/contest/967/problem/E 题目大意: 给你一个数组a,a的长度为n 定义:b(i) = a(1)^a(2)^......^a(i), 问, ...
- Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D 贪心
http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x ...
- VK Cup 2017 - Qualification 1 C 贪心
是一道很有趣的题目 给出地图和起始点 与要求的步数k 要求走k步 正好回到起始点 输出字典序最小的移动路径 DLRU这样 可以想到DU LR都是相同数量的 于是k必须是一个偶数 然后走了弯路QAQ 从 ...
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题
E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- VK Cup 2015 - Finals, online mirror D. Restructuring Company 并查集
D. Restructuring Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线
题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...
随机推荐
- QRadioButton分组且无边框的简单实现
最近在用QT+VS2008做一个项目,涉及到一个综合测评表,说白了有点像问卷调查——很多题目每题若干个选项. 初始时打算用下拉框,每个框中填入所有选项,但后来一琢磨这种方式不够直观与人性化,增添了一步 ...
- angularJS中-$route路由-$http(ajax)的使用
后台请求使用的是nodeJS驱动(后面帖代码),很简单的RESTFUL, 页面使用的是bottstarp3.0(懒人神器); 第一个例子: 在本地架设NODEJS, angular的所有请求都是请求本 ...
- Xdebug开源PHP程序调试器
Xdebug是一个开放源代码的PHP程序调试器(即一个Debug工具),可以用来跟踪,调试和分析PHP程序的运行状况. 本文为大家讲解的是在linux下xdebug的安装和配置方法,感兴趣的同学参考下 ...
- [Windows 64] (搬运)价值¥ 6,499的软件Navicat Premium11.2.11 最新版及其注册机
Navicat Premium可以连接6种数据库并开发> 转载于:http://www.52pojie.cn/thread-529020-1-1.html
- ansible-1 的安装
该文章摘自:http://my.oschina.net/firxiao/blog/343395,该文章制作笔记使用,不做他用,转载请注明原文链接出处 Ansible 默认是基于SSH协议进行通信的. ...
- Linux大文件已删除,但df查看已使用的空间并未减少解决
在我的生活当中遇到磁盘快满了,这时候准备去删除一些大文件 于是我使用ncdu 查看了一下当前系统占用资源比较多的是那些文件,结果一看是elasticsearch的日志文件,好吧,竟然找到源头了,那就把 ...
- WebForm之Linq组合查询
组合查询 protected void Button1_Click(object sender, EventArgs e) { //默认查询所有,返回的是Table类型,转换成IQueryAble类型 ...
- Html-Css-iframe的使用
iframe是作为在网页中嵌套网页的标签 <iframe src="homeIndex_init.html" width="100%" height=&q ...
- Java基础-JVM
jvm=> java虚拟机 一.java虚拟机的生命周期: Java虚拟机的生命周期 一个运行中的Java虚拟机有着一个清晰的任务:执行Java程序.程序开始执行时他才运行,程序结束时他就停止. ...
- Yii2登陆添加验证码
models中 LoginForm.php public $verifyCode; public function rules() { return [ …… ['verifyCode', 'capt ...