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 }
  • 相关阅读:
    shell脚本:Kill掉MySQL中所有sleep的client线程
    为什么事务要提交或者回滚?
    MySQL 性能优化
    解决:Reading table information for completion of table and column names
    mysql distinct 用法详解及优化
    MySQL Profiling 的使用
    手把手教你用Strace诊断问题[转]
    mysql,命令导入导出表结构或数据
    八种架构设计模式及其优缺点概述(下)
    mysql多实例配置下,用脚本启动mysql时,出现Please read "Security" section of the manual to find out how to run mysqld as root!
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/6329680.html
Copyright © 2011-2022 走看看