题目链接:

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 (暴力)的更多相关文章

  1. SGU 506.Subsequences Of Substrings

    求一个串S有多少子串subS满足s是subS的子序列.len(S)<=100000, len(s)<=100 直接扫一遍... ------------------------------ ...

  2. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

  3. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  4. SDU暑期集训排位(4)

    SDU暑期集训排位(4) C. Pick Your Team 题意 有 \(n\) 个人,每个人有能力值,A 和 B 轮流选人,A 先选,B 选人按照一种给出的优先级, A 可以随便选.A 想最大化己 ...

  5. Kattis之旅——Divisible Subsequences

    Given a sequence of positive integers, count all contiguous subsequences (sometimes called substring ...

  6. POJ1226 Substrings ——后缀数组 or 暴力+strstr()函数 最长公共子串

    题目链接:https://vjudge.net/problem/POJ-1226 Substrings Time Limit: 1000MS   Memory Limit: 10000K Total ...

  7. hdu1238 Substrings (暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=1238 Substrings Time Limit : 2000/1000ms (Java/Other)   Me ...

  8. Java实现 蓝桥杯 算法提高VIP Substrings(暴力)

    试题 算法提高 Substrings 问题描述 You are given a number of case-sensitive strings of alphabetic characters, f ...

  9. hdu 1238 Substrings(kmp+暴力枚举)

    Problem Description You are given a number of case-sensitive strings of alphabetic characters, find ...

随机推荐

  1. Redis高并发和快速的原因

    一.Redis的高并发和快速原因 1.redis是基于内存的,内存的读写速度非常快: 2.redis是单线程的,省去了很多上下文切换线程的时间:   3.redis使用多路复用技术,可以处理并发的连接 ...

  2. Day20--Python--约束和异常处理

    1. 异常处理(处理异常,抛出异常,自定义异常) 异常: 程序运行过程中产生的错误 1. 产生异常. raise 异常类(), 抛出异常 2. 处理异常: try: xxxxxxxx # 尝试执行的代 ...

  3. POJ 2240 Arbitrage (Bellman Ford判正环)

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:27167   Accepted: 11440 Descri ...

  4. (count 或直接枚举) 统计字符 hdu1860

    统计字符(很水) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1860 Time Limit: 1000/1000 MS (Java/Others)    ...

  5. MySQL8常见客户端和启动相关参数

    MySQL8常见客户端和启动相关参数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL常见的客户端 1>.使用MySQL服务自带的mysql连接工具 2>. ...

  6. powershell 定时删除脚本

    powershell  定时删除脚本 $today=Get-Date #"今天是:$today" #昨天 #"昨天是:$($today.AddDays(-1))" ...

  7. namenode format

    https://community.hortonworks.com/content/supportkb/48981/how-to-recover-namenode-ha-when-one-accide ...

  8. 面向对象【day08】:动态导入模块(八)

    本节内容 1.概述 2.知识回顾 3.动态导入模块 一.概述 我们之前导入模块都是用import,或者from ... import ....这种模式去导入模块,那如果我们如何实现只用字符串就可以导入 ...

  9. java用流的方式加载图片

    前端: <img ng-show="photo" class="vertical_b" id="photoImg" src=" ...

  10. MAC上截图,编辑图片与恢复图片

    1.Command+shift+3:全屏截图,保存截图到桌面 2.Command+shift+4:鼠标选定区域截图,保存截图到桌面 3.Command+shift+4+Space(空格键):程序窗口截 ...