Codeforces 392 B Blown Garland
题意:输入是由连续的RYGB和字符!组成的字符串,R代表红灯,Y代表黄灯,G代表绿灯,B代表蓝灯。简而言之,就是给定的字符串保证了下标对4取余相同的灯颜色都相同,但是有的地方为‘!’代表这个灯坏了,然后分别输出坏了的红、蓝、黄、绿灯的数量。
分析:因为下标对4取余相同的灯颜色都相同,所以确定了前四个灯的颜色,后面的灯都是前四个灯颜色的不断循环,两个map映射一下就可以了。
#include<bits/stdc++.h>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
char s[MAXN];
map<int, char> mp;
map<char, int> ma;
int a[];
int main(){
ma['R'] = ;
ma['B'] = ;
ma['Y'] = ;
ma['G'] = ;
while(scanf("%s", s) == ){
mp.clear();
memset(a, , sizeof a);
int len = strlen(s);
for(int i = ; i < len; ++i){//确定前四个灯的颜色
if(i % == && s[i] != '!'){
mp[] = s[i];
}
if(i % == && s[i] != '!'){
mp[] = s[i];
}
if(i % == && s[i] != '!'){
mp[] = s[i];
}
if(i % == && s[i] != '!'){
mp[] = s[i];
}
}
for(int i = ; i < len; ++i){
if(s[i] == '!'){
int t = i % ;
char c = mp[t];//每个坏了的灯分别是什么颜色,并统计个数
++a[ma[c]];
}
}
printf("%d %d %d %d\n", a[], a[], a[], a[]);
}
return ;
}
Codeforces 392 B Blown Garland的更多相关文章
- 【codeforces 758B】Blown Garland
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 758B:Blown Garland(模拟)
http://codeforces.com/problemset/problem/758/B 题意:给出一个字符串,每4个位置对应一个颜色,如果为‘!’的话,代表该灯泡是坏的,问最后每个颜色坏的灯泡的 ...
- 758B Blown Garland
B. Blown Garland time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces758B Blown Garland 2017-01-20 10:19 87人阅读 评论(0) 收藏
B. Blown Garland time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces 758B Blown Garland
题目链接:http://codeforces.com/contest/758/problem/B 题意:一个原先为4色环的链子少了部分,要你找出死的最少的一种可能,各输出四种颜色的死了多少. 分析:就 ...
- B. Blown Garland
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 1.23 codeforces div3 C.Nice Garland
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ...
- CF codeforces A. New Year Garland【Educational Codeforces Round 79 (Rated for Div. 2)】
A. New Year Garland time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 140E.New Year Garland
传送门: 解题思路: 要求相邻两行小球颜色集合不同,并且限制行内小球相邻不同. 由此可得:每行小球排列都是独立与外界的, 所以答案应该是对于所有行的颜色集合分类,在将行内的答案乘到上面. 先考虑如何分 ...
随机推荐
- 转:Nginx的超时keeplive_timeout配置详解
https://blog.csdn.net/weixin_42350212/article/details/81123932 Nginx 处理的每个请求均有相应的超时设置.如果做好这些超时时间的限定, ...
- php 等于不等于 一个感叹号两个等于号
$a == $b 等于 TRUE,如果 $a 等于 $b. $a === $b 全等 TRUE,如果 $a 等于 $b,并且它们的类型也相同.(PHP 4 引进) $a != $b 不等 TRUE,如 ...
- 常见加密解密 -- pycryptodomex库
安装 windows pip install pycryptodomex ubuntu pip install pycryptodome 加密方式 单向加密:MD5 只能对数据进行加密,而不能解密 对 ...
- C# 篇基础知识7——字符串
文字是信息的主要表达方式,因此文字处理是计算机的一项重要功能之一.现在来深入研究C#中字符串的各种特性.正则表达式的基本概念以及如何用正则表达式进行文本匹配. 1.char结构 C#中的字符用Syst ...
- Redis使用守护进程启动sentinel并指定其日志目录
正常redis-server可以通过配置文件来指定守护进程启动以及指定日志路径,但sentinel就不一样了.正常启动redis的sentinel时,进程会直接在前台跑,一退出sentinel进程就关 ...
- 终于解决ERROR: PHP's 'ldap' extension is not installed/enabled. Please check your MR
我的系统是centos,php是yum的5.6.40,php-ldap也是yum的5.6.40,配置好ldap后,登录时提示ERROR: PHP's 'ldap' extension is not i ...
- JavaBean是什么
作者:杨博链接:https://www.zhihu.com/question/19773379/answer/31625054来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...
- zabbix WebUI自定义Nginx监控项模板
zabbix webUI自定义Nginx监控项模板 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.创建模板 1>.如下图所示,依次点击"配置" --- ...
- 将OB86的故障信息保存在DB86中去
出现DP站故障的时候,CPU会自动调用OB86 ,OB86 的20B 局部变量里面有丰富的故障信息,生成数据块DB86 在DB86 中生成5个双字元素的数组ARAY 在OB86中调用 "BL ...
- linux systemctl命令
转自systemctl详解 systemctl 是系统服务管理器命令,它实际上将 service 和 chkconfig 这两个命令组合到一起. 任务 旧指令 新指令 使某服务自动启动 chkconf ...