Educational Codeforces Round 32 Problem 888C - K-Dominant Character
1) Link to the problem: http://codeforces.com/contest/888/problem/C
2) Description:
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant if 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 character.
The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).
Print one number — the minimum value of k such that there exists at least one k-dominant character.
3) 思路:
这题的tag居然是binary search,我做的时候基本没往这方面想。
我的思路就是算每个字母的maxgap然后求最小。
数据长度最长是10^5,然后26个字母注意:大小写要区分。
最后大概是O(n)左右,time limit是2s。所以肯定能过。O(n^2)的话就不用想了,O(n^2)属于不理智行为。
4) Code:
#include <iostream>
#include <cstring>
using namespace std;
int main(){
string s;
cin>>s;
int n = s.size();
int min = INT_MAX; for(int i = ; i < ; i++)
{
char c;
if(i<)
c = (char)('a' + i);
else
c = (char)('A' + i - ); int count = ;
int maxgap = ;
for(int j = ; j < n; j++){
if(s[j] == c)
{
if(maxgap < count)
maxgap = count;
count = ;
}
else {
count ++;
}
}
if(maxgap < count)
maxgap = count;
if(maxgap < min)
min = maxgap;
if(min==)
break;
}
cout << min + ;
return ;
}
Educational Codeforces Round 32 Problem 888C - K-Dominant Character的更多相关文章
- Educational Codeforces Round 32
http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...
- Educational Codeforces Round 21 Problem A - C
Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...
- Educational Codeforces Round 21 Problem D(Codeforces 808D)
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...
- Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案
Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...
- Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist ...
- Educational Codeforces Round 32 Almost Identity Permutations CodeForces - 888D (组合数学)
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in thi ...
- Educational Codeforces Round 32 E. Maximum Subsequence
题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往 ...
- Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)
题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很 ...
随机推荐
- Memcache随笔
Tip01: Memcache 中记录的缓存如果你设置了失效时间,之后如果你在系统时间中将时间修改为超过失效时间,再次访问之前你设置的资源,Memcache 会认为你设置的缓存已失效: Tip02: ...
- 如何应用SPRITEKIT的CAMERA实现游戏中的ENDLESS无限循环背景
A Tutorial For How To Use SpriteKit Camera Making Endless Background Player运用Camera节点向前移动的效果 向前舞动 命为 ...
- phpStudy环境安装SSL证书教程(apache)
https://cloud.tencent.com/product/ssl 此链接是检测域名 证书的可以检测一下 下面是证书配置 小白呢亲测 作为PHP程序员,我们一定要学会使用phpStudy环境集 ...
- 用jQuery实现(全选、反选、全不选功能)
在jQuery选择器的基础下我们实现一个全选,反选,全不选功能! <script type="text/javascript"> $(function ( ...
- 第九篇:S3C2400时钟体系
S3C2400时钟体系 S3C2400时钟配置流程 该学习板使用了外部晶振12Mhz 晶振--->经过MPLL(锁相环) --->(倍频得到)FCLK--->(对FCLK分频得到)H ...
- Java学习笔记二十四:Java中的Object类
Java中的Object类 一:什么是Object类: Object类是所有类的父类,相当于所有类的老祖宗,如果一个类没有使用extends关键字明确标识继承另外一个类,那么这个类默认继承Object ...
- HttpClient的Content-Type设置
HttpClient的Content-Type设置 最近在对接公司内容的一个云服务的时候,遇到一个问题,就是如果使用HttpClient如何设置post时候的Content-Type? public ...
- 20154327 Exp4 恶意代码分析
基础问题回答 (1)如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作有哪些,用什么方法来监控. 监控网络连接 监控是否创建新的进程 监控 ...
- 北京Uber优步司机奖励政策(12月8日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- JavaScript---设计模式之职责链模式
概念 职责链模式是使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这个对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理他为止. 链中收到请求的对象要么亲自处理它,要 ...