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 ...
随机推荐
- Day30--Python--struct, socketserver
1. struct struct.pack 打包 def pack(fmt, *args): # known case of _struct.pack """ pack( ...
- RabbitMQ入门-发布订阅模式
兔子的Publish/Subscribe是这样的: 有个生产者P,X代表交换机,交换机绑定队列,消费者从队列中取得消息.每次有消息,先发到交换机中,然后由交换机负责发送到它已知的队列中. 生产者代码: ...
- tensor flow中summary用法总结
对于用法的总结详细的参见博文https://www.cnblogs.com/lyc-seu/p/8647792.html
- android studio adb.exe已停止工作(全面成功版 进程的查询和开启)
先输入adb看是否存在. 如果不存在则:在系统path里添加C:\Users\nubia\AppData\Local\Android\sdk\platform-tools 因为这个目录里有adb 或者 ...
- js数组歌
判断是不是数组,isArray最靠谱. 按照条件来判断,every/some给答案 是否包含此元素,includes最快速. find/findIndex很相似,按条件给第一个值. indexOf/l ...
- (二叉树 bfs) leetcode 199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...
- (Dijkstra) POJ1797 Heavy Transportation
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 53170 Accepted: ...
- vue(基础一)_基本指令的使用
一.前言 1.基本骨架 2.插值表达式{{ }} 3.vue起的作用,在开发中充当的角色MVC ...
- ajax请求封装函数
写封装函数的套路 1.先写出这个函数原来的基本用法 2.写一个没有形参空函数,将上一步的代码直接作为函数体, 3.根据使用过程中,抽象出来需要变的东西作为形参 function ajax (metho ...
- java 中二维数组的定义和遍历
定义格式 * a 第一种定义格式: * int[][] arr = new int[3][4];// arr里面包含3个数组 每个数组里面有四个元素 * 上面的代码相当于定义了一个3*4的二维数组,即 ...