题意:输入是由连续的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的更多相关文章

  1. 【codeforces 758B】Blown Garland

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. Codeforces 758B:Blown Garland(模拟)

    http://codeforces.com/problemset/problem/758/B 题意:给出一个字符串,每4个位置对应一个颜色,如果为‘!’的话,代表该灯泡是坏的,问最后每个颜色坏的灯泡的 ...

  3. 758B Blown Garland

    B. Blown Garland time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. 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 ...

  5. Codeforces 758B Blown Garland

    题目链接:http://codeforces.com/contest/758/problem/B 题意:一个原先为4色环的链子少了部分,要你找出死的最少的一种可能,各输出四种颜色的死了多少. 分析:就 ...

  6. B. Blown Garland

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  7. 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 ...

  8. 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 ...

  9. codeforces 140E.New Year Garland

    传送门: 解题思路: 要求相邻两行小球颜色集合不同,并且限制行内小球相邻不同. 由此可得:每行小球排列都是独立与外界的, 所以答案应该是对于所有行的颜色集合分类,在将行内的答案乘到上面. 先考虑如何分 ...

随机推荐

  1. 「SCOI2010」幸运数字

    传送门 Luogu 解题思路 首先构造出所有的幸运数字. 然后考虑一个幸运数字会产生多少贡献. 对于一个数 \(x\),它在区间 \([l,r]\) 内的倍数的个数为 \(\lfloor \frac{ ...

  2. leetcode347 Top K Frequent Elements

    """ Given a non-empty array of integers, return the k most frequent elements. Example ...

  3. CF755G PolandBall and Many Other Balls 题解

    从神 Karry 的题单过来的,然后自己瞎 yy 了一个方法,看题解区里没有,便来写一个题解 一个常数和复杂度都很大的题解 令 \(dp_{i,j}\) 为 在 \(i\) 个球中选 \(j\) 组的 ...

  4. BUU easyre

    拖入ida中shift+F12查找字符串就可以看到flag

  5. ubuntu 系统分配固定 ip--

    由于Ubuntu重启之后,ip很容易改变,可以用以下方式固定ip地址 1.设置ip地址 vi /etc/network/interface # The loopback network interfa ...

  6. SQLI_LAB------level 1

    SQLI_LAB 刷题刷题刷题!!! 知识扩展: SQL 1)SQL注入介绍 SQLI,sql injection,我们称之为 sql 注入.何为 sql,英文:Structured Query La ...

  7. R 误差自相关与DW检验

    R语言进行DW检验: library(lmtest) dw = dwtest(fm1) > dw Durbin-Watson test data: fm1 DW = 2.4994, p-valu ...

  8. WEB-INF

    WEB-INF下的内容是没有办法通过浏览器去请求的.可以把东西放在WEB-INF下面,避免用户直接通过浏览器请求.那些资源只允许通过url请求过来通过其他途径转发给用户. 比如WEB-INF/jsp/ ...

  9. Vulkan SDK Demo 之一 熟悉

    DiligentEngine的API是D3d11和D3D12风格的,vulkan也被封装成了这种风格的API. 在了解Diligent Engine是如何对vulkan进行封装之前,我准备先学习下Vu ...

  10. ErrorCode=-2147217900 表已存在.

    ErrorCode=-2147217900 表已存在. 在导出excel时遇到这个问题. 原因是dataTable的TableName中有减号 "-"