【codeforces 758B】Blown Garland
来源:互联网 发布:软件开发语言培训 编辑:程序博客网 时间:2024/05/19 13:06
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
【题目链接】:http://codeforces.com/contest/758/problem/B
【题解】
枚举前4个的排列;
4!
然后根据前4个推出整个序列应该是什么;
看看合法不合法;
合法的话看!对应的是什么;输出就好了;
4!*100;
肯定不超;
【完整代码】
#include <bits/stdc++.h>using namespace std;string ts,s;bool bo[4];int len,ans[4];bool ok(string ss){ // cout << len << endl; // cout << ss <<endl; int tlen = 0; string ts2=""; while (tlen<len) { ts2+=ss; tlen+=4; } for (int i = 0;i <= len-1;i++) if (s[i]!='!' && s[i]!=ts2[i]) return false; for (int i = 0;i <= len-1;i++) if (s[i]=='!') { if (ts2[i]=='R') ans[0]++; if (ts2[i]=='B') ans[1]++; if (ts2[i]=='Y') ans[2]++; if (ts2[i]=='G') ans[3]++; } for (int i = 0;i<=2;i++) printf("%d ",ans[i]); printf("%d\n",ans[3]); return true;}void sear_ch(int now,string temp){ if (now==4) { if (ok(temp)) exit(0); return; } for (int i =0;i<=3;i++) if (!bo[i]) { bo[i] = true; sear_ch(now+1,temp+ts[i]); bo[i] = false; }}int main(){ //freopen("F:\\rush.txt","r",stdin); cin >> s; len = s.size(); ts = "RBYG"; memset(bo,false,sizeof bo); sear_ch(0,""); return 0;}
- 【codeforces 758B】Blown Garland
- Codeforces 758B-Blown Garland
- CodeForces 758B Blown Garland
- 【Codeforces 758 Blown Garland】
- Codeforces #392 B. Blown Garland
- codeforces-758-B Blown Garland(简单数学)
- Codeforces Round #392 (Div. 2) 758B Blown Garland
- cf 758 B. Blown Garland模拟
- Blown Garland CodeForces
- B. Blown Garland
- CF-Codeforces Round #392 (Div. 2)-B-Blown Garland
- Codeforces Round #392 (Div. 2) B - Blown Garland
- Codeforces Round #392 (Div. 2)-B. Blown Garland(水题)
- Codeforces Round #392(Div. 2) B Blown Garland【暴力枚举】
- Codeforces Round #392 (Div. 2)B Blown Garland
- Codeforces Round #392 (Div. 2) B.Blown Garland(水题)
- Codeforces Round #392 (Div. 2) B. Blown Garland
- Codeforces Round #392 (Div. 2) B. Blown Garland(规律)
- gstreamer播放器,playbin2插件使用,适合新来gstreamer
- 克服跨洋网络延迟,使用Docker Hub Mirror加速Docker官方镜像下载
- [bsoj1035] 点和线
- maven类型的web工程本地调试办法
- C#打开文件 ,文件夹
- 【codeforces 758B】Blown Garland
- Android多线程间通信
- 继承和派生
- 2017美国数学建模MCM A题(连续型)翻译 管理赞比西河 Managing The Zambezi River
- manacher板子
- 关于Trie KMP AC自动机
- [bsoj1922] 机器蛇
- Android studio之代码注释
- android_85_自定义View