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 ...
随机推荐
- Java:静态代理 and 动态代理
代理模式是常用的设计模式,其特征是代理类与委托类具有相同的接口,在具体实现上,有静态代理和动态代理之分.代理类与委托类之间通常会存在关联关系,一个代理类的对象与一个委托类的对象关联,代理类的对象本身并 ...
- 风清杨之Oracle的安装与说明
1.Oracle官网与下载地址 Oracle中文官网:http://www.oracle.com/cn/index.html Oracle中文官网下载:http://www.oracle.com/te ...
- 你应当如何学习C++(以及编程)(转载)
你应当如何学习C++(以及编程)(rev#1) By 刘未鹏(pongba) C++的罗浮宫(http://blog.csdn.net/pongba) Javascript是世界上最受误解的语言,其实 ...
- ubuntu中管理用户和用户组
1. 添加一个用户组并指定id为1002 sudo groupadd -g 1002 www 2. 添加一个用户到www组并指定id为1003 sudo useradd wyx -g 1002 -u ...
- C#线程模型脉络
今天在看同事新买到的<C#本质论 Edition 4>的时候,对比下以前Edtion3的新特性时针对Async/Await关键字时发现对一些线程方面的定义还理解的不是很透彻,脉络还不是很清 ...
- 团队项目作业第二项:利用NABCD模型进行竞争性需求分析
项目需求分析与建议--NABCD模型(王鲁跃负责) N (Need 需求) 对于现在的学生来说,我们认为打字是很重要的.不管在什么方面都需要进行电脑打字,例如文员.QQ.MSN.制作,论文等等,都需要 ...
- navjs
'use strict';define([ 'jquery'], function($) { var nav = { init : function() { $("#burger-menu& ...
- MVC2 Area实现网站多级目录
Areas是ASP.NET Mvc 2.0版本中引入的众多新特性之一,它可以帮你把一个较大型的Web项目分成若干组成部分,即Area.实现Area的功能可以有两个组织形式: 在1个ASP.NET Mv ...
- iOS边练边学--iOS中的json数据解析
JSON数据(NSData) -> OC对照表 {} -> NSDictionary @{} [] -> NSArray @[] "jack" -> NSS ...
- oracle-分页查询方案
一.使用rownum做三层包装查询(常用方案) SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM TABLE_NAME) A ) 其中 ...