题目: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. C# 压缩和解压文件(SharpZipLib)

    先从网上下载ICSharpCode.SharpZipLib.dll类库 将文件或文件夹压缩为zip,函数如下 /// <summary> /// 压缩文件 /// </summary ...

  2. 剑指 offer set 16 数字在排序数组中出现的次数

    总结 1. Leetcode 上有一道题, 求某一个数字在有序数组中出现的最左位置和最右位置, 而这道题就是那题的变形

  3. 让iOS应用支持不同版本的系统与设备

    本文转载至  http://blog.csdn.net/pucker/article/details/11980811 最近一直在做app的iOS 6和7的同时适配工作,所以在此介绍一下系统与设备的兼 ...

  4. DNS rebinging攻击方式

    一.什么是DNS rebinding? 在dns协议中,请求和响应完成一台机器对一个域名的查询,响应信息包含请求域名站点对应的IP地址.假设你向DNS服务器A请求域名youself.domain.co ...

  5. 三 Android Studio打包EgretApp (SDK选择和下载)

    一 设置项目的sdk路径 二 设置项目使用sdk版本 一 设置项目的sdk路径 设置SDK目录 选择你电脑上的sdk路径 二 在项目中设置SDK版本 在项目中设置编译的sdk版本 在SDK Manag ...

  6. Java使用Apache POI进行Excel导入和导出

    Manve依赖 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> ...

  7. 160316、实时处理oracle数据库中表的数据变化

    http://blog.csdn.net/as339000204/article/details/45390727     近期接受项目需求,需要实时处理oracle数据库中表的数据变化,首先想到的是 ...

  8. poj3585 Accumulation Degree【树形DP】【最大流】

    Accumulation Degree Time Limit: 5000MS   Memory Limit: 65536K Total Submissions:3151   Accepted: 783 ...

  9. ubuntu下安装myeclipse+破解

    1.给myeclipseInstaller.run权限 chmod myeclipseInstaller.run 2.安装(结束时不启动,去掉√) ./myeclipseInstaller.run 3 ...

  10. Spring Cloud Zuul与网关中间件

    Spring Cloud Zuul与网关中间件_网易订阅 http://dy.163.com/v2/article/detail/DC7L8UV10511HSJK.html