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
传送门: 解题思路: 要求相邻两行小球颜色集合不同,并且限制行内小球相邻不同. 由此可得:每行小球排列都是独立与外界的, 所以答案应该是对于所有行的颜色集合分类,在将行内的答案乘到上面. 先考虑如何分 ...
随机推荐
- 检测皮肤PH值、感知你的便意,健康是可穿戴设备的新风口?
在经历最初的喧嚣与疯狂后,可穿戴设备近年来有些低调和沉寂.换句话说,虽然可穿戴设备销量在持续走高,但从形态和功能上,呈现出高度一致性.这似乎也在证明着,可穿戴设备已成为寻常可见的普通产品而已.不过在迈 ...
- tomcat项目已存在错误
Could not publish server configuration for Apache Tomcat v8.0-1 at localhost.Multiple Contexts have ...
- Linux CentOS7 VMware 安装软件包的三种方法、rpm包介绍、rpm工具用法、yum工具用法、yum搭建本地仓库
一.安装软件包的三种方法 Linux下游三种安装方法,rpm工具.yum工具.源码包.rpm按装一个程序包时,有可能因为该程序包依赖另一个程序包而无法安装:yum工具,可以连同依赖的程序包一起安装. ...
- 第一章、ssh安装及远程登入配置
1.Ubuntu下 确认 SSH Server 是否启动 输入: sudo ps -e | grep ssh. 如果正确启动, 命令行中会显示sshd. 安装服务端 OpenSSH Server 输入 ...
- CSP-S 2019 复赛游记
自闭游记 >_< Day 0 随便敲了一些板子 当然打了摆. 奶人的话写满了俩黑板啊,没人奶我可海星. 晚上没怎么打摆,随便敲了几道板子,然后很早就回去睡了. Day 1 平静地出发了.. ...
- bootstrap fileinput控件上传文件大小限制
部分js: language: "zh",//设置语言 showCaption: true,//是否显示标题 showUpload: true, //是否显示上传按钮 showPr ...
- mac java 装机清单
1. JDK8 2. Eclipse IDE for Enterprise Java Developers 3. maven 4. Postman 5. VS Code 6. finalshell ( ...
- 虚拟机下安装win7
参考博客:https://blog.csdn.net/weixin_43465312/article/details/92662519 下载地址:https://msdn.itellyou.cn/
- nuxt.js 初始化 npm run dev 报错
在初始化 npm install 了基本依赖后: npm run dev 报错: error in ./server/index.js Module build failed: Error: Plug ...
- DBlink查看,创建于删除
1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...