zoukankan      html  css  js  c++  java
  • XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures

    题目: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
    ",ans);
    34     return 0;
    35 }
    standard input standard output
    MKHMKMKHMHKKMHKMHHKKKHKMM 3


    思路:

      贪心扫。

  • 相关阅读:
    青松云安全-WAF-1.0.655 (ubuntu 14.04 server)
    相似变换和仿射变换
    参数坐标系统变换
    城市测量坐标系统的建立
    工程测量坐标系
    大地测量控制点坐标转换技术规范
    为什么样本方差(sample variance)的分母是 n-1?
    似大地水准面
    typedef的用法
    同一椭球面经纬度坐标与空间直角坐标之间的相互转换
  • 原文地址:https://www.cnblogs.com/weeping/p/7291979.html
Copyright © 2011-2022 走看看