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 ...
随机推荐
- 使用python制作验证码
方法一 简单型:使用random模块制作一个随机字母与数字的验证码 import random def make_code(n): res='' for i in range(n): num=str( ...
- 第八节、图片分割之GrabCut算法、分水岭算法
所谓图像分割指的是根据灰度.颜色.纹理和形状等特征把图像划分成若干互不交迭的区域,并使这些特征在同一区域内呈现出相似性,而在不同区域间呈现出明显的差异性.我们先对目前主要的图像分割方法做个概述,后面再 ...
- tensor flow中summary用法总结
对于用法的总结详细的参见博文https://www.cnblogs.com/lyc-seu/p/8647792.html
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:co
在pom中加入下面代码: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId&g ...
- nginx根据cookie分流
转载互联网 nginx根据cookie分流众所周知,nginx可以根据url path进行分流,殊不知对于cookie分流也很强大,同时这也是我上篇提到的小流量实验的基础. 二话不说,先看需求,两台服 ...
- rownum查询前N条记录
在Oracle中,要按特定条件查询前N条记录,用个rownum就搞定了.——select * from emp where rownum <= 5 而且书上也告诫,不能对rownum用" ...
- Word 测试下发布博客
目录 语法. 3 NULL,TRUE,FALSE 3 大小端存储 4 类型转换 4 转义字符 5 运算符的优先级 5 表达式(a=b=c) 7 *pa++=* ...
- nGrinder TestRunner XFF / X-Forwarded-For
s 我们在压测请求报文里面带了这个"x-forward-for":"10.24.51.132"这个字段,所以我们所有的压测请求穿透到应用系统的时候,应用系统上采 ...
- 简单的jvm优化的尝试
一.eclipse 启动优化 在日常的开发中发现eclipse 启动的时候非常慢,并且在实际的开发中也非常卡,所以尝试着优化一下.现在eclipse 是运行在jdk1.7上. 首先我们可以看到ecli ...
- nginx的下载、编译安装和启动
一.nginx简介 nginx(“engine x”)是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器.nginx是由Igor Sysoev为俄罗斯访问量第二的R ...