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 ...
随机推荐
- CDC类
CDC :class of device context Windows使用与设备无关的图形设备环境(DC :Device Context) 进行显示 .MFC基础类库定义了设备环境对象类----CD ...
- 与Python Falling In Love_Python跨台阶(环境搭建)
Python--环境搭建 首先需要下载python安装包,官网下载地址:https://www.python.org/downloads/ 下载完直接点击安装... 安装完后就可以配置环境变量咯^_^ ...
- 将Mininet与真实网络相连接
原文发表在我的博客主页,转载请注明出处 前言 Mininet是SDN网络仿真的一大利器,在小规模网络模拟使用上独领风骚,其开源性允许使用者按照自己的需求修改源码,得到想要的数据,其提供了多个函数用来满 ...
- C++实现反射机制
NET下的很多技术都是基于反射机制来实现的,反射让.NET平台下的语言变得得心应手.最简单的,比如枚举类型,我们我可以很容易的获得一个枚举变量的数值以及其名称字符串. 可是,在C++中,枚举变量本质上 ...
- 01.C#数据类型、排序、过滤(一章1.1-1.2)
随着看的文章及探讨越多,越发现自己实在太不定性了,看下<C#深入理解>吧,做一下读书笔记,从中发现自己的不足.闲话不说,进入正题吧. 在C#1中定下一个简单的数据类型 public cla ...
- jQuery基础之(五)jQuery自定义添加"$"与解决"$"的冲突
1.自定义添加$ 从上面四篇文章我们看到jQuery的强大,但无论如何,jQuery都不可能满足所有用户的需求,而且有一些需求十分小众,也不适合放到整个jQuery框架中,正是因为这一点,jQuery ...
- 每天一个linux命令(49):ss命令
ss是Socket Statistics的缩写.顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容.但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信 ...
- SQL基础知识总结(一)
1.union 和union all 操作符 1)union内部的select语句必须拥有相同的列,列也必须有相似的数字类型.同时,每条select语句中列的顺序相同. union语法(结果集无重复) ...
- Maven 教程
Maven 教程 序:几次对Maven 的学习,都因为各种原因 而中途切断了,再一次学习的时候,又不得不重新开始,结果发现 又不记得步骤 又找不到对应的文档.别人写的再好,终究比不过自己亲手实践的得出 ...
- CentOS/Redhat VNC 服务
# yum install vnc-server vnc* (CentOS 5.x)# yum install tigervnc-server tigervnc (CentOS 6.x) [root@ ...