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

题目: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

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 #define MP make_pair
 6 #define PB push_back
 7 typedef long long LL;
 8 typedef pair<int,int> PII;
 9 const double eps=1e-8;
10 const double pi=acos(-1.0);
11 const int K=1e6+7;
12 const int mod=1e9+7;
13 
14 char ss[K];
15 int ans;
16 int main(void)
17 {
18     int len;
19     scanf("%s",ss+1);
20     len=strlen(ss+1);
21     ss[0]='K';
22     for(int i=1;i<=len;i++)
23     if(ss[i]!='K')
24     {
25         int ta=0,tb=0;
26         for(i;i<=len;i++)
27         if(ss[i]=='M')  ta++;
28         else if(ss[i]=='H') tb++;
29         else if(tb>0) tb--;
30         else break;
31         ans=max(ans,ta);
32     }
33     printf("%d\n",ans);
34     return 0;
35 }

 

standard input standard output
MKHMKMKHMHKKMHKMHHKKKHKMM 3


思路:

  贪心扫。

 

转载于:https://www.cnblogs.com/weeping/p/7291979.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值