题意:输入是由连续的RYGB和字符!组成的字符串,R代表红灯,Y代表黄灯,G代表绿灯,B代表蓝灯。简而言之,就是给定的字符串保证了下标对4取余相同的灯颜色都相同,但是有的地方为‘!’代表这个灯坏了,然后分别输出坏了的红、蓝、黄、绿灯的数量。

分析:因为下标对4取余相同的灯颜色都相同,所以确定了前四个灯的颜色,后面的灯都是前四个灯颜色的不断循环,两个map映射一下就可以了。

  1. #include<bits/stdc++.h>
  2. #define Min(a, b) ((a < b) ? a : b)
  3. #define Max(a, b) ((a < b) ? b : a)
  4. const int INT_INF = 0x3f3f3f3f;
  5. const int INT_M_INF = 0x7f7f7f7f;
  6. const int dr[] = {, , -, , -, -, , };
  7. const int dc[] = {-, , , , -, , -, };
  8. const int MOD = 1e9 + ;
  9. const double pi = acos(-1.0);
  10. const double eps = 1e-;
  11. const int MAXN = + ;
  12. const int MAXT = + ;
  13. using namespace std;
  14. char s[MAXN];
  15. map<int, char> mp;
  16. map<char, int> ma;
  17. int a[];
  18. int main(){
  19. ma['R'] = ;
  20. ma['B'] = ;
  21. ma['Y'] = ;
  22. ma['G'] = ;
  23. while(scanf("%s", s) == ){
  24. mp.clear();
  25. memset(a, , sizeof a);
  26. int len = strlen(s);
  27. for(int i = ; i < len; ++i){//确定前四个灯的颜色
  28. if(i % == && s[i] != '!'){
  29. mp[] = s[i];
  30. }
  31. if(i % == && s[i] != '!'){
  32. mp[] = s[i];
  33. }
  34. if(i % == && s[i] != '!'){
  35. mp[] = s[i];
  36. }
  37. if(i % == && s[i] != '!'){
  38. mp[] = s[i];
  39. }
  40. }
  41. for(int i = ; i < len; ++i){
  42. if(s[i] == '!'){
  43. int t = i % ;
  44. char c = mp[t];//每个坏了的灯分别是什么颜色,并统计个数
  45. ++a[ma[c]];
  46. }
  47. }
  48. printf("%d %d %d %d\n", a[], a[], a[], a[]);
  49. }
  50. return ;
  51. }

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. 检测皮肤PH值、感知你的便意,健康是可穿戴设备的新风口?

    在经历最初的喧嚣与疯狂后,可穿戴设备近年来有些低调和沉寂.换句话说,虽然可穿戴设备销量在持续走高,但从形态和功能上,呈现出高度一致性.这似乎也在证明着,可穿戴设备已成为寻常可见的普通产品而已.不过在迈 ...

  2. tomcat项目已存在错误

    Could not publish server configuration for Apache Tomcat v8.0-1 at localhost.Multiple Contexts have ...

  3. Linux CentOS7 VMware 安装软件包的三种方法、rpm包介绍、rpm工具用法、yum工具用法、yum搭建本地仓库

    一.安装软件包的三种方法 Linux下游三种安装方法,rpm工具.yum工具.源码包.rpm按装一个程序包时,有可能因为该程序包依赖另一个程序包而无法安装:yum工具,可以连同依赖的程序包一起安装. ...

  4. 第一章、ssh安装及远程登入配置

    1.Ubuntu下 确认 SSH Server 是否启动 输入: sudo ps -e | grep ssh. 如果正确启动, 命令行中会显示sshd. 安装服务端 OpenSSH Server 输入 ...

  5. CSP-S 2019 复赛游记

    自闭游记 >_< Day 0 随便敲了一些板子 当然打了摆. 奶人的话写满了俩黑板啊,没人奶我可海星. 晚上没怎么打摆,随便敲了几道板子,然后很早就回去睡了. Day 1 平静地出发了.. ...

  6. bootstrap fileinput控件上传文件大小限制

    部分js: language: "zh",//设置语言 showCaption: true,//是否显示标题 showUpload: true, //是否显示上传按钮 showPr ...

  7. mac java 装机清单

    1. JDK8 2. Eclipse IDE for Enterprise Java Developers 3. maven 4. Postman 5. VS Code 6. finalshell ( ...

  8. 虚拟机下安装win7

    参考博客:https://blog.csdn.net/weixin_43465312/article/details/92662519 下载地址:https://msdn.itellyou.cn/

  9. nuxt.js 初始化 npm run dev 报错

    在初始化 npm install 了基本依赖后: npm run dev 报错: error in ./server/index.js Module build failed: Error: Plug ...

  10. DBlink查看,创建于删除

    1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...