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 }
  • 相关阅读:
    Symbian点滴3对象的创建和释放以及对象的二阶段构造
    SQL 列转行
    HashMap详解
    SpringCloudEureka工作原理及和ZooKeeper的区别
    Redis如何使redis中存放数据都为热点数据,缓存算法,key的淘汰策略
    线程的三种实现方式详解
    Redis缓存雪崩,缓存穿透,缓存击穿,缓存预热概念及解决方案
    mysql系列——连接查询(七)
    SpringCloud服务雪崩,降级 ,熔断
    hdu 2215 Maple trees
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/6329680.html
Copyright © 2011-2022 走看看