题目链接:http://codeforces.com/problemset/problem/519/D 题目大意:给你一串字符串s仅由小写字母组成,并且对于'a'~'z'都给了一个值.求子串t满足t的开头和结尾字符相同,且中间的字符的值相加为0,求子串t的数目.解题思路:设置map<LL,int>mp[26]这样的二维map,记录对应以每个字母结尾的前缀和的值的出现次数.然后计算前缀和sum,每次计算sum+val[s[i]]前,先计算ans,因为sum[i-1]-sum[x]==0才能说明s…
题意:给出26个字母每个字母的价值,问字符串中有多少个满足以下条件的子串: 1.子串的第一个和最后一个相同 2.子串除了头和尾的其他字符的价值加起来和尾0 这题普通方法应该是O(n^2),但是在1e5的条件下肯定会超时,所以学习了大力学长奥义的O(n)方法.具体方法也说不清楚,看代码吧,很短,也容易看懂.只能说,相当奥义的方法.. 代码如下: #include <stdio.h> #include <algorithm> #include <string.h> #inc…
A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB"…
D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. After several years of doing sports program…
传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. After several years of doing sports pro…
A:http://codeforces.com/problemset/problem/519/A 水题没什么好说的. #include <iostream> #include <string.h> #include <stdio.h> #include <math.h> #include <algorithm> #include <queue> #define inf 0x3f3f3f3f using namespace std; ]…
题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求有多少长度大于1的子串满足: 1)首尾字符相同. 2)除了首尾字符外,其他字符的权值和为0. 题目分析 使用STL Map.开26个Map,给每个字母开一个. 先求出权值的前缀和 Sum[] . 然后1到l枚举每一位字符,如果是a,那么 Ans += Map[a][Sum[i - 1]]; 然后 +…
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <map> #include <queue> #includ…
题意: 对于26个字母 每个字母分别有一个权值 给出一个字符串,找出有多少个满足条件的子串, 条件:1.第一个字母和最后一个相同,2.除了第一个和最后一个字母外,其他的权和为0 思路: 预处理出sum[i]:s[0~i]的和 开26个map<LL, LL>numV 分别表示 每个字母前缀和 的个数 例如处理到第i个元素,且numV[s[i]-'a'][sum[i]-v[s[i] - 'a']] (值为2) 表示在处理到的元素之前 以s[i]结尾的前缀和为sum[i]-v[s[i]-'a']的个…
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bough…
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/problem/A Description You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "…
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉得是拼手速的题啊,结果瞬间就一发WA,连pretest都没通过, 然后开始想,发现没那么简单的样子,很多坑的样子,当我写了2个循环把AB BA 都扫一遍时, 认为考虑周全后,觉得能过了,就交,过了pretest,当时看room里面 大多数还没过A呢,觉得很高兴. 然后学长说这题能叉很多人,我不懂什么…
题目链接:https://codeforces.com/contest/1367/problem/A 题意 给出一个字符串 $t$,找出原字符串 $s$,$t$ 由 $s$ 从左至右的所有长为 $2$ 的子串构成. 题解 只有 $s$ 的首尾字符会只在 $t$ 中出现一次,其余字符都会重复出现两次. 代码 #include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; int n =…
题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的按位与和至少为多少. 更新时,如果val的pos位为1,那么整个区间的按位与和pos位也应该为1,否则与出来就不对了.(这是本题解题的核心) 那么此时更新 sum[rt] |= val 即可.然后再check一遍看是否满足所有条件即可. 代码: #include <iostream> #inclu…
题意: 已知26个小写字母有各自的权值(正,负,或0) 现在给出一个字符串,长度<=1e5 问这个字符串有多少个子串满足: 开头的字母和结尾的字母一样 字符串除了开头和结尾的字母外,其余的字母的权值和为0 本来是一道水题,一看就知道大体的思路了,结果硬是搞了一个多小时 先是用set,发现超时了,改为用map 思路: 1.我们先预处理这个字符串的权值的前缀和 sum[i]表示从字符串的起点到i的权值和 2.我们要找到的子串,设以l开头和r结尾,则有 str[r] == str[l] 和 sum[r…
题意 给出$26$个字母对应的权值和一个字符串 问满足以下条件的子串有多少 首尾字母相同 中间字母权值相加为0 Sol 我们要找到区间满足$sum[i] - sum[j] = 0$ $sum[i] = sum[j]$ 开$26$个map维护一下$sum$相等的子串就可以 /* */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map…
题意 https://vjudge.net/problem/CodeForces-519D 给定每个小写字母一个数值,给定一个只包含小写字母的字符串 s,求 s 的子串 t 个数,使 t满足: 首位字母相同,长度大于 1. 首尾字母除外的其余字母的数值之和为 0. 思路 考虑abca的值为1 1 -1 1,前缀和为1 2 1 0,用map维护每个字符的各前缀和的个数,设两个a位置分别为l,r,那么对于后一个a它的答案是map[a][preR],因为l+1~r-1的和为0,所以pre[L]=pre…
B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/problem/B Description Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clea…
A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/problem/A Description Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", a…
题目链接: 题目 D. Alyona and Strings time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output 问题描述 After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are…
题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It's hard times now. Today Petya needs to score 100 points on Informatics…
#1152 : Lucky Substrings时间限制:10000ms单点时限:1000ms内存限制:256MB描述A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Given a string consisting of only lower case letters, output all its lucky non-empty substrin…
题目链接:http://codeforces.com/contest/777/problem/D 题解: 题意:给出n行字符串,对其进行字典序剪辑.我自己的想法是正向剪辑的,即先对第一第二个字符串进行剪辑,但是这样却不能保证前面的操作是正确的,当后面突然出现一个字典序很小的字符串,那么前面的操作将非法.这种方法错在不能预知正在操作的字符串的字典序限度.看了别人的代码,发现是反向进行剪辑的,即从倒数第一第二个字符串进行剪辑,直到第一个.因为倒数第一个的字典序必须是最大,所以倒数第二个的字典序限度已…
题目链接:http://codeforces.com/problemset/problem/632/C C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You're given a list of n strings a1, a2, ..., an. Y…
Description You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.    Input The first line of the input file co…
[题意]给n个字符串组成的集合,然后有m个询问(0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) ,每个询问都给出一个字符串s,问集合中是否存在一个字符串t,使得s和t长度相同,并且仅有一个字符不同.(字符串总长度为6·105),所有字符只有a,b,c. [题解]因为只有三种字符,用Trie最合适.先把n个字符串插入到Trie中.然后每读入一个字符串,首先枚举差异字符的位置,依次替换为另外两种字符,并检查是否合法.如果合法就直接输出YES. 显然每替换一个字符就从头检查一遍太浪费时间,…
A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems…
B. Split a Number time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard output Dima worked all day and wrote down on a long paper strip his favorite number n consisting of l digits. Unfortunately, the stri…
A. Helpful Maths time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.…