hihocoder offer收割编程练习赛11 A hiho字符串
思路:
我用的尺取。
注意题目描述为恰好2个'h',1个'i',1个'o'。
实现:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std; const int INF = 0x3f3f3f3f; int ch[], ci[], co[]; bool check(int pos, int a, int b, int c)
{
return ch[pos] <= a - && ci[pos] <= b - && co[pos] <= c - ;
} int main()
{
string s;
cin >> s;
int n = s.length();
ch[] += (s[] == 'h');
ci[] += (s[] == 'i');
co[] += (s[] == 'o');
int last = , min_len = INF;
for (int i = ; i < n; i++)
{
ch[i] = ch[i - ] + (s[i] == 'h');
ci[i] = ci[i - ] + (s[i] == 'i');
co[i] = co[i - ] + (s[i] == 'o');
if (ch[i] >= && ci[i] >= && co[i] >= )
{
while (last < i && check(last, ch[i], ci[i], co[i]))
{
last++;
}
if (ch[i] - ch[last - ] == &&
ci[i] - ci[last - ] == &&
co[i] - co[last - ] == )
min_len = min(min_len, i - last + );
}
}
if (min_len != INF)
cout << min_len << endl;
else
cout << - << endl;
return ;
}
hihocoder offer收割编程练习赛11 A hiho字符串的更多相关文章
- hihocoder offer收割编程练习赛11 D 排队接水
思路: 莫队算法+树状数组. 莫队算法的基本思想是对大量要查询的区间进行离线处理,按照一定的顺序计算,来降低复杂度.概括来说,我们在知道了[l, r]的解,并且可以通过一个较低的复杂度推出[l - 1 ...
- hihocoder offer收割编程练习赛11 C 岛屿3
思路: 并查集的应用. 实现: #include <iostream> #include <cstdio> using namespace std; ][]; int n, x ...
- hihocoder offer收割编程练习赛11 B 物品价值
思路: 状态压缩 + dp. 实现: #include <iostream> #include <cstdio> #include <cstring> #inclu ...
- hihocoder [Offer收割]编程练习赛4
描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...
- hihocoder [Offer收割]编程练习赛61
[Offer收割]编程练习赛61 A:最小排列 给定一个长度为m的序列b[1..m],再给定一个n,求一个字典序最小的1~n的排列A,使得b是A的子序列. 贪心即可,b是A的子序列,把不在b中的元素, ...
- [hihocoder][Offer收割]编程练习赛43
版本号排序 不知道什么傻逼原因,就是过不了 #pragma comment(linker, "/STACK:102400000,102400000") #include<st ...
- ACM学习历程—Hihocoder [Offer收割]编程练习赛1
比赛链接:http://hihocoder.com/contest/hihointerview3/problem/1 大概有一个月没怎么打算法了.这一场的前一场BC,也打的不是很好.本来Div1的A和 ...
- hihocoder offer收割编程练习赛8 C 数组分拆
思路:(引自bfsoyc的回答:http://hihocoder.com/discuss/question/4160) 动态规划.状态dp[i]表示 前i个数的合法的方案数,转移是 dp[i] = s ...
- 【[Offer收割]编程练习赛11 B】物品价值
[题目链接]:http://hihocoder.com/problemset/problem/1486 [题意] [题解] 设f[i][j]表示前i个物品,每种属性的状态奇偶状态为j的最大价值; 这里 ...
随机推荐
- 2016/2/25 onchange 应用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ibatis和mybatis的区别
区别1:全局配置文件(sqlMapConfig.xml)的差异 主要是元素标签命名的差异,比如mybatis的根元素标签为<configuration>,ibatis的 根元素标签为< ...
- windows安装SVN服务器并设置开机启动
1.安装SVN服务器,到http://subversion.apache.org/packages.html上下载windows版的SVN,并安装,在命令行下运行svn命令,如下所以,则svn服务器安 ...
- java 编码设置
- 深入分析linux调度机制
一.说明 本文以linux-2.4.10 为例主要分析Linux 进程调度模块中的schedule 函数及其相关的函数.另外相关的前提知识也会说明.默认系统平台是自己的i386 架构的pc. 二.前提 ...
- 【Linux 内核网络协议栈源码剖析】网络栈主要结构介绍(socket、sock、sk_buff,etc)
原文:http://blog.csdn.net/wenqian1991/article/details/46700177 通过前面的分析,可以发现,网络协议栈中的数据处理,都是基于各类结构体,所有有关 ...
- ZOJ3261 Connections in Galaxy War —— 反向并查集
题目链接:https://vjudge.net/problem/ZOJ-3261 In order to strengthen the defense ability, many stars in g ...
- 【T^T 1736】【FJUTOJ 1077】排座位
http://59.77.139.92/problem.php?id=1077 水题,小心PE // <1736.cpp> - 11/12/16 17:17:52 // This file ...
- linux下修改apache,nginx服务端口号
一.linux下修改apache端口号 yum安装后,apache配置文件: /etc/httpd/conf/httpd.conf 找到apache目录下的 httpd.conf, 使用vi 打开,找 ...
- bzoj1296 [SCOI2009]粉刷匠——背包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1296 对于不同木板之间,最终统计答案时做一个分组背包即可: 而要进行分组背包,就需要知道每个 ...