K-Dominant Character CodeForces - 888C】的更多相关文章

题目链接:https://vjudge.net/problem/CodeForces-888C 划一条线,使得不论怎么划线,都会出现一个特定的字符,那么这条线最短要多长. 用字符间隔考虑. 先判断哪些字符出现了,然后统计每个不同字符的出现次数,出现一次的和出现多次的分开判断. 出现一次的找到它的位置,取max(当前位置 - 字符串开始位置 + 1,字符串末位位置 - 当前位置 + 1), 然后遍历所有出现一次的字符,得出max的最小值,并记录,dis1 出现多次的找到相邻两个相同字符的间隔,取最…
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c. You have to find minimum k such that there exists at least one k-dominant chara…
题目:Problem - C - Codeforces 如代码,一共有七种情况,注意不要漏掉  "accabba"  , "abbacca"  两种情况: 使用find()函数可简化代码,使用方法如下 代码: #include <iostream> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.ti…
题意: 给出 n 个数,选取其中若干个数分别组成至多 k 组,要求每组内最大值与最小值的差值不超过5,求最后被选上的总人数. 题解: 将a[1∼n] 从小到大排序, f[i][j] 表示到第 i 个数为止,已经组成 j 组,最多可以包含多少个数. 那么,考虑第 i 个数选取与否,如果不选,那么 , 如果选,那么必然是第 i 个数所在组人数加上前面那些组人数,假设 p 表示距离 a[i]左侧最远的那个位置(满足 ),这里是指p之前的那些组的人数 题目链接: https://cn.vjudge.ne…
Problem K. UTF-8 Decoder 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022&all_runs=1&action=140 Description UTF-8 is a character encoding capable of encoding all possible characters, or code points, in Unicode. Nowadays…
E - Dominant Indices CodeForces - 1009F You are given a rooted undirected tree consisting of nn vertices. Vertex 11 is the root. Let's denote a depth array of vertex xx as an infinite sequence [dx,0,dx,1,dx,2,…][dx,0,dx,1,dx,2,…], where dx,idx,i is t…
Given a non-empty string str and an integer k, rearrange the string such that the same characters are at least distance k from each other. All input strings are given in lowercase letters. If it is not possible to rearrange the string, return an empt…
Given a string, find the length of the longest substring T that contains at most k distinct characters. For example, Given s = "eceba" and k = 2, T is "ece" which its length is 3. 我的做法:维护一个window,r移动到超出k distinct character限制是更新max,然后移动…
Given a string, find the longest substring that contains only two unique characters. For example, given "abcbbbbcccbdddadacb", the longest substring that contains k unique character is "bcbbbbcccb". 分析: 用hashmap记录每个character从start到当前位置…
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28214 题目大意:源串有如下变形:每次将串切为两半,位置颠倒形成新串.问经过K次变形后,与目标串相同的变形方案数.mod 1000000007. 解题思路: 奇葩的字符串DP.照着别人的题解写的,解释不出原理是什么. 首先统计出经过1次变形,就能和目标串相同的中间产物串(包含源串)的个数cnt.len表示源串长度,那么len-cnt就表示和目标串不同的个数. 用…