zoukankan      html  css  js  c++  java
  • B. Blown Garland

    http://codeforces.com/problemset/problem/758/B

    B. Blown Garland
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.

    Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.

    It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.

    Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.

    Input

    The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:

    • 'R' — the light bulb is red,
    • 'B' — the light bulb is blue,
    • 'Y' — the light bulb is yellow,
    • 'G' — the light bulb is green,
    • '!' — the light bulb is dead.

    The string s can not contain other symbols except those five which were described.

    It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.

    It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.

    Output

    In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.

    Examples
    Input
    RYBGRYBGR
    Output
    0 0 0 0
    Input
    !RGYB
    Output
    0 1 0 0
    Input
    !!!!YGRB
    Output
    1 1 1 1
    Input
    !GB!RG!Y!
    Output
    2 1 1 0
    Note

    In the first example there are no dead light bulbs.

    In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.

     思路:因为每个字都会至少给出一个,我们知道a[i] == a[i+4],a[i] == a[i-4],如果不是话就不能构成连续4

    个都不同。那么直接模拟添加。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 char str[3000];
     5 map<char,int>my;
     6 int flag[5];
     7 int cnt[5];
     8 int main(void)
     9 {
    10     scanf("%s",str);
    11     int l = strlen(str);
    12     char c;
    13     c = 'R';
    14     my[c] = 1;
    15     c = 'B';
    16     my[c] = 2;
    17     c = 'Y';
    18     my[c] = 3;
    19     c = 'G';
    20     my[c] = 4;
    21     memset(cnt,0,sizeof(cnt));
    22     while(true)
    23     {   int c = 0;
    24        for(int i = 0;i < l;i++)
    25        {
    26           if(str[i] != '!')
    27           {
    28               if(i-4 >= 0&&str[i-4]=='!')
    29               {
    30                   str[i-4] =  str[i];
    31                   cnt[my[str[i]]]++;
    32                   c = 1;
    33               }
    34               if(i+4 < l&&str[i+4]=='!')
    35               {
    36                   str[i+4] = str[i];
    37                   cnt[my[str[i]]]++;
    38                   c = 1;
    39               }
    40           }
    41        }
    42        if(!c)break;
    43     }int sum = 0;
    44     for(int i = 0;i < l;i++)
    45     {
    46         if(str[i] == '!')
    47         {
    48             sum++;
    49         }
    50     }
    51     for(int i = 1;i <= 4;i++)
    52         cnt[i]+=sum/4;
    53     //puts(str);
    54     printf("%d",cnt[1]);
    55     for(int i = 2; i <= 4; i++)
    56         printf(" %d",cnt[i]);
    57     return 0;
    58 }
  • 相关阅读:
    搭建一个redis高可用系统
    从“如何设计用户超过1亿的应用”说起----数据库调优实战
    单表60亿记录等大数据场景的MySQL优化和运维之道 | 高可用架构
    信息安全系统和安全体系
    敏捷开发系列之旅 第五站(不一样的RUP统一软件开发过程)
    微服务理论与实践(三)-微服务架构的基本能力和优缺点
    学习“CC攻击”
    查看IIS错误日志
    ISNULL函数
    IE6/7下Select控件Display属性无效解决办法
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/6329680.html
Copyright © 2011-2022 走看看