题目:Problem D. Clones and Treasures
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 mebibytes
The magical treasury consists of n sequential rooms. Due to construction of treasury its impossible to
go from room with biggest number to room in smallest number, i.e. from first hall one can go only to
second, from second — to third etc.
Each room in treasury may be inhabitated by a clone of ancient king Koschey the Immortal, or, if it is
not inhabitated by a clone, room may contain one gold coin or the invisibility potion which allows become
invisible for time enought to pass only one room with a clone; each not inhabitated room contains exactly
one of those items.
Ivan plans to enter the treasury and collect as much money as possible without being noticed by the
clones of Koschey. He may choose the room where he starts his adventure, then go through some rooms;
at any room he may cast the spell and leave the treasury, but then he will not be able to return anymore.
How much gold coins collects Ivan if he will act optimally?
Input
Input contains one string of length n (1 ≤ n ≤ 106) — map of the treasury. Rooms are listed from lest
to right; character ‘H’ denotes invisibility potion, character ‘M’ — one gold coin, character ‘K’ — clone of
Koschey. String cannot contain characters different than those ones.
Output
Print one integer — maximum amount of gold coins Ivan can collect.
Example

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; char ss[K];
int ans;
int main(void)
{
int len;
scanf("%s",ss+);
len=strlen(ss+);
ss[]='K';
for(int i=;i<=len;i++)
if(ss[i]!='K')
{
int ta=,tb=;
for(i;i<=len;i++)
if(ss[i]=='M') ta++;
else if(ss[i]=='H') tb++;
else if(tb>) tb--;
else break;
ans=max(ans,ta);
}
printf("%d\n",ans);
return ;
}
standard input standard output
MKHMKMKHMHKKMHKMHHKKKHKMM 3

思路:

  贪心扫。

XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures的更多相关文章

  1. 【推导】【贪心】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures

    给你一行房间,有的是隐身药水,有的是守卫,有的是金币. 你可以任选起点,向右走,每经过一个药水或金币就拿走,每经过一个守卫必须消耗1个药水,问你最多得几个金币. 药水看成左括号,守卫看成右括号, 就从 ...

  2. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative

    题目:Problem A. Arithmetic DerivativeInput file: standard inputOutput file: standard inputTime limit: ...

  3. 【二分】【字符串哈希】【二分图最大匹配】【最大流】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem I. Minimum Prefix

    给你n个字符串,问你最小的长度的前缀,使得每个字符串任意循环滑动之后,这些前缀都两两不同. 二分答案mid之后,将每个字符串长度为mid的循环子串都哈希出来,相当于对每个字符串,找一个与其他字符串所选 ...

  4. 【二分图】【并查集】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel

    给你一个网格(n<=2000,m<=2000),有一些炸弹,你可以选择一个空的位置,再放一个炸弹并将其引爆,一个炸弹爆炸后,其所在行和列的所有炸弹都会爆炸,连锁反应. 问你所能引爆的最多炸 ...

  5. 【动态规划】【滚动数组】【bitset】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal

    有两辆车,容量都为K,有n(10w)个人被划分成m(2k)组,依次上车,每个人上车花一秒.每一组的人都要上同一辆车,一辆车的等待时间是其停留时间*其载的人数,问最小的两辆车的总等待时间. 是f(i,j ...

  6. 【枚举】【最小表示法】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game

    给你一个n*m的字符矩阵,将横向(或纵向)全部裂开,然后以任意顺序首尾相接,然后再从中间任意位置切开,问你能构成的字典序最大的字符串. 以横向切开为例,纵向类似. 将所有横排从大到小排序,枚举最后切开 ...

  7. 【推导】【构造】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem E. Space Tourists

    给你n,K,问你要选出最少几个长度为2的K进制数,才能让所有的n位K进制数删除n-2个元素后,所剩余的长度为2的子序列至少有一个是你所选定的. 如果n>K,那么根据抽屉原理,对于所有n位K进制数 ...

  8. 【找规律】【DFS】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative

    假设一个数有n个质因子a1,a2,..,an,那么n'=Σ(a1*a2*...*an)/ai. 打个表出来,发现一个数x,如果x'=Kx,那么x一定由K个“基础因子”组成. 这些基础因子是2^2,3^ ...

  9. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game

    题目: Problem F. Matrix GameInput file: standard inputOutput file: standard inputTime limit: 1 secondM ...

随机推荐

  1. 【翻译】Webpack 4 从0配置到生产模式

    查看原文 webpack 4 发布了! webpack 4 作为一个零配置的模块打包器 webpack 是强大的并且有许多独一无二的特点但是有一个痛点就是配置文件. 在中型到大型项目中为webpack ...

  2. tomcat下载与安装..使用和配置环境变量

    操作环境: xp, myEclipse6.5 tomcat6.0 正文: 一.下载 tomcat官方网站 http://tomcat.apache.org 在左边Download树形菜单中 点击最新版 ...

  3. iOS UILable 高度自适

    #import "ViewController.h" #define FontSize 20 @interface ViewController () @end @implemen ...

  4. Eclipse启动Server报错:Could not publish to the server. java.lang.NullPointerException

    转载自:http://m.blog.csdn.net/article/details?id=49862243 错误信息: publishing to tomcat v8.0 server at loc ...

  5. 使用Fastjson生成Json字符串少字段属性(数据丢失)

    最后是控制台打印生成的结果如下:FastJson生成字符串是:{"id":"2","name":"节点1"," ...

  6. 数组和对象常用API

    数组API: 1. forEach 遍历所有元素 var arr = [1,2,3] arr.forEach(function(item,index){ // 遍历数组的所有元素 console.lo ...

  7. C++中,将单精度浮点数转换成2进制数

    在C++里,实数(float)是用四个字节即三十二位二进制位来存储的.其中有1位符号位,8位指数位和23位有效数字位.实际上有效数字位是24位,因为第一位有效数字总是"1",不必存 ...

  8. Spring--简记

    Spring通过一个配置文件描述Bean及Bean之间的依赖关系,利用Java语言的反射功能实例化Bean并建立Bean之间的依赖关系. Spring的IoC(控制反转)容器提供了Bean实例缓存.生 ...

  9. 查看环境变量CLASSPATH, PATH ,JAVA_HOME-------->mac

    终端(命令行)操作 推荐两篇博客:http://elf8848.iteye.com/blog/1582137 http://blog.csdn.net/done58/article/details/5 ...

  10. Xcode升级了6.3 出现的警告:Auto property synthesis will not synthesize property

    1.  Auto property synthesis will not synthesize property 'title'; it will be implemented by its supe ...