Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)
题目链接:
Subsequences in Substrings
Kattis - subsequencesinsubstrings
题目大意:给你字符串s和t。然后让你在s的所有连续子串中,找出这些连续子串中的非连续子串中包含t的有多少个。
具体思路:我们枚举s的每一个位置,然后判断一下s的包含t的非连续子串中到达那个位置,然后这个字符串两边的长度相乘就是当前位置开始,满足条件的字符位置。然后我们在找从上一次找到首字母位置下一个开始, 继续往下找就可以了。
AC代码:
- #include<bits/stdc++.h>
- using namespace std;
- # define ll long long
- const int maxn = 4e5+;
- int main()
- {
- ios::sync_with_stdio(false);
- string s,t;
- cin>>s>>t;
- ll len1=s.size();
- ll len2=t.size();
- ll ans=;
- ll pos=-;
- while()
- {
- int st,ed;
- st=s.find(t[],pos+);
- if(st==-)break;
- ed=st;
- for(int i=;i<len2;i++){
- ed=s.find(t[i],ed+);
- if(ed==-)break;
- }
- if(ed==-)break;
- ans+=(st-pos)*(len1-ed);
- pos=st;
- }
- printf("%lld\n",ans);
- }
Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)的更多相关文章
- SGU 506.Subsequences Of Substrings
求一个串S有多少子串subS满足s是subS的子序列.len(S)<=100000, len(s)<=100 直接扫一遍... ------------------------------ ...
- SGU题目总结
SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- SDU暑期集训排位(4)
SDU暑期集训排位(4) C. Pick Your Team 题意 有 \(n\) 个人,每个人有能力值,A 和 B 轮流选人,A 先选,B 选人按照一种给出的优先级, A 可以随便选.A 想最大化己 ...
- Kattis之旅——Divisible Subsequences
Given a sequence of positive integers, count all contiguous subsequences (sometimes called substring ...
- POJ1226 Substrings ——后缀数组 or 暴力+strstr()函数 最长公共子串
题目链接:https://vjudge.net/problem/POJ-1226 Substrings Time Limit: 1000MS Memory Limit: 10000K Total ...
- hdu1238 Substrings (暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=1238 Substrings Time Limit : 2000/1000ms (Java/Other) Me ...
- Java实现 蓝桥杯 算法提高VIP Substrings(暴力)
试题 算法提高 Substrings 问题描述 You are given a number of case-sensitive strings of alphabetic characters, f ...
- hdu 1238 Substrings(kmp+暴力枚举)
Problem Description You are given a number of case-sensitive strings of alphabetic characters, find ...
随机推荐
- 第三十二节,使用谷歌Object Detection API进行目标检测、训练新的模型(使用VOC 2012数据集)
前面已经介绍了几种经典的目标检测算法,光学习理论不实践的效果并不大,这里我们使用谷歌的开源框架来实现目标检测.至于为什么不去自己实现呢?主要是因为自己实现比较麻烦,而且调参比较麻烦,我们直接利用别人的 ...
- Gym 101915
Gym - 101915A Printing Books 题意:有一本书,从第X页开始,一共用了n位数字,求此书一共多少页.99就是两位数字,100就是三位数字. 思路:直接模拟即可,我用了一个hi ...
- C内存分配
calloc和realloc与malloc的区别 calloc和realloc的原型如下: void *calloc ( size_t num_elements, size_t element_siz ...
- (BFS) leetcode 690. Employee Importance
690. Employee Importance Easy 377369FavoriteShare You are given a data structure of employee informa ...
- (set) 人见人爱A-B hdu2034
人见人爱A-B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- SSM结构
代码结构为 src:controller / mapper / entity / service /(serviceiml) webcontent:META-INF WEB-INF:lib(包含所 ...
- 剑指Offer_编程题_6
题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个 ...
- Normal Equation
一.Normal Equation 我们知道梯度下降在求解最优参数\(\theta\)过程中需要合适的\(\alpha\),并且需要进行多次迭代,那么有没有经过简单的数学计算就得到参数\(\theta ...
- flume常见异常汇总以及解决方案
flume常见异常汇总以及解决方案 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 实际生产环境中,我用flume将kafka的数据定期的往hdfs集群中上传数据,也遇到过一系列的坑 ...
- 面向对象【day07】:析构函数(六)
二.析构函数 一.概述 析构函数,第一次听说这个函数的名称,那这个函数到底是干嘛的呢?什么才是析构函数呐? 定义:在实例销毁的时候调用的函数 二.析构函数定义 2.1 定义 1 2 3 4 5 6 7 ...