Codeforces Round #392 (Div. 2) 758B Blown Garland
来源:互联网 发布:linux make 退出 编辑:程序博客网 时间:2024/06/16 12:52
题目传送门:点击打开链接
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.
The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, thei-th symbol of which describes the color of thei-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.
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.
RYBGRYBGR
0 0 0 0
!RGYB
0 1 0 0
!!!!YGRB
1 1 1 1
!GB!RG!Y!
2 1 1 0
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.
题意:现在有R Y B G 四种颜色的灯泡排成一排。已知每四个相邻的灯泡不会有重复的颜色。现在这排灯泡上有些灯坏掉了,标记为感叹号。请你输出这排灯泡坏之前的情况。
我们可以注意下题目所给的样例:RYBGRYBGRY YBGRYBGRYBG
你会发现,相同字母之间一定会夹着三个字母.。 比如:第一组中的R与R之间一定隔着三个字母。
得到这个结论以后,我们会发现,相同字母出现的下标%4都是相同的。
#include<bits/stdc++.h>using namespace std;#define LL long long#define M(a) memset(a,0,sizeof(a))char str[105];int num[5];int main(){ while(~scanf("%s",str)) { M(num); int r,b,g,y; int len=strlen(str); for(int i=0; i<len; i++) { if(str[i]=='R') { r=i%4; } else if(str[i]=='B') { b=i%4; } else if(str[i]=='Y') { y=i%4; } else if(str[i]=='G') { g=i%4; } else { num[i%4]++; } } printf("%d %d %d %d\n",num[r],num[b],num[y],num[g]); } return 0;}
- Codeforces Round #392 (Div. 2) 758B 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(规律)
- Codeforces Round #392(Div. 2) B Blown Garland【暴力枚举】
- Codeforces Round #392 (Div. 2)Blown Garland
- 【codeforces 758B】Blown Garland
- Codeforces 758B-Blown Garland
- CodeForces 758B Blown Garland
- Codeforces #392 B. Blown Garland
- Codeforces Round #239 (Div. 2) B. Garland
- 【Codeforces 758 Blown Garland】
- codeforces-758-B Blown Garland(简单数学)
- Android studio安装使用教程(详细图文教程)
- ReactNative爬坑-小记<Image/>控件通过json数据加载App里drawable中图片资源
- 翻译:AVPlayerItemOutput
- 理解mysql_锁的概念
- Java中关于内存泄漏出现的原因以及如何避免内存泄漏
- Codeforces Round #392 (Div. 2) 758B Blown Garland
- 使用MultipartEntity对文字、图片、视频进行综合上传
- Python学习笔记——闭包
- 数据结构==二叉树(数组实现)
- ny-32-组合数
- GDB List no symbol table is loaded
- 理解mysql_limit优化思路
- 陈纪修老师《数学分析》 第06章:不定积分 笔记
- 求数组中出现次数超过一半的数字