Codeforces Round #392(Div. 2) B Blown Garland【暴力枚举】

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.


题目大意:

一共有四种颜色的灯RBYG,现在有!处表示这个位子的灯泡坏掉了,我们现在需要在!处放置四种颜色的灯泡,使得最终的序列,保证每连续的四个灯泡都具有四种不同的颜色。问我们需要添加多少个R,B,Y,G.

保证答案唯一。


思路(虽然这个思路笨了点,代码量稍微大了一点,不过在CF这种场次上来讲,这么做是最不会FST的):


我们观察到一共就四种颜色,那么一共这四种颜色的排列方式有多少种呢?答案很明显是4的阶乘(24)种,那么我们不妨Dfs枚举出来这24种排列方式,然后按照每一种方式向原串进行匹配,对应每4个都是枚举出来的当前方案,即为可行方案。

假设我们枚举出来的是YGBR那么答案串就应该是:YGBRYGBRYGBR.............................(如果这样的串和原串中不是!的灯泡的颜色都对上了,那么对应这个答案就是那个唯一解);

维护过程,判断出唯一解的排列顺序之后,维护最终答案。


Ac代码:

include<stdio.h>
#include<string.h>
using namespace std;
char a[150];
char b[150];
int contz[150];
int use[150];
int ok;
int tmp[150];
char judge(int num)
{
    if(num==1)return 'R';
    if(num==2)return 'B';
    if(num==3)return 'Y';
    if(num==4)return 'G';
}
void Slove()
{
    memset(contz,0,sizeof(contz));
    int n=strlen(a);
    for(int i=0;i<n;i++)
    {
        if(a[i]=='!')
        {
            int pos=i%4;
            b[i]=judge(tmp[pos]);
            contz[judge(tmp[pos])]++;
        }
        else
        {
            int pos=i%4;
            b[i]=judge(tmp[pos]);
            if(b[i]!=a[i])return ;
        }
    }
    for(int i=1;i<n;i++)
    {
        if(b[i]==b[i-1])return ;
    }
    ok=1;
    printf("%d %d %d %d\n",contz['R'],contz['B'],contz['Y'],contz['G']);
    return ;
}
void Dfs(int now)
{
   // if(ok==1)return ;
    if(now==4)
    {
        Slove();
        return ;
    }
    for(int i=1;i<=4;i++)
    {
        if(use[i]==0)
        {
            tmp[now]=i;
            use[i]=1;
            Dfs(now+1);
            use[i]=0;
        }
    }
}
int main()
{
    while(~scanf("%s",a))
    {
        ok=0;
        memset(use,0,sizeof(use));
        Dfs(0);
    }
}







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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值