Codeforces758B Blown Garland 2017-01-20 10:19 87人阅读 评论(0) 收藏
1 second
256 megabytes
standard input
standard output
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, the i-th symbol of which describes the color of the i-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.
YBGRYBGRYBG,
BGRYB,!表示坏了的灯
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string> using namespace std; char a[1006];
int main()
{
while(~scanf("%s",a))
{
int k=strlen(a);
int r,g,b,y;
int c[10005];
int cnt=0;
for(int i=0; i<k; i++)
{
if(a[i]=='!')
{
c[cnt++]=i;
}
else if(a[i]=='R')
{
r=i;
}
else if(a[i]=='G')
{
g=i;
}
else if(a[i]=='B')
{
b=i;
} else if(a[i]=='Y')
{
y=i;
}
}
r%=4;
g%=4;
b%=4;
y%=4;
int R=0,G=0,B=0,Y=0;
for(int i=0;i<cnt;i++)
{
if(c[i]%4==r)
R++;
else if(c[i]%4==g)
G++;
else if(c[i]%4==b)
B++;
else if(c[i]%4==y)
Y++;
}
printf("%d %d %d %d\n",R,B,Y,G);
}
return 0;
}
Codeforces758B Blown Garland 2017-01-20 10:19 87人阅读 评论(0) 收藏的更多相关文章
- ubuntu中安装eclipse 分类: android ubuntu linux 学习笔记 2015-07-07 10:19 75人阅读 评论(0) 收藏
上一篇说了安装jdk的事,于是趁热打铁,决定把eclipse也安装了. 下载这一系列就不用说了. 下载完成之后: 然后解压,解压之后文件剪切到/usr/software文件夹中,同时重命名为eclip ...
- sscanf 函数 分类: POJ 2015-08-04 09:19 4人阅读 评论(0) 收藏
sscanf 其实很强大 分类: 纯C技术 技术笔记 2010-03-05 16:00 12133人阅读 评论(4) 收藏 举报 正则表达式stringbuffercurlgoogle 最近在做日志分 ...
- 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏
文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...
- C语言基础总结 分类: iOS学习 c语言基础 2015-06-11 10:08 23人阅读 评论(0) 收藏
//欲练此功必先自宫!!! //第一天:C语言的基础 //进制 //2进制, 10进制, 8进制, 16进制 //注:8进制数前加0, 16进制数前加0x ...
- Financial Management 分类: POJ 2015-06-11 10:51 12人阅读 评论(0) 收藏
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 164431 Accepted: ...
- Hangover 分类: POJ 2015-06-11 10:34 12人阅读 评论(0) 收藏
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 108765 Accepted: 53009 Descr ...
- DateTime日期格式获取 分类: C# 2014-04-15 10:36 233人阅读 评论(0) 收藏
c#.net 获取时间年月日时分秒格式 //获取日期+时间 DateTime.Now.ToString(); // 2008-9-4 20:02:10 DateTime.Now. ...
- winform timespan 两个时间的间隔(差) 分类: WinForm 2014-04-15 10:14 419人阅读 评论(0) 收藏
TimeSpan 结构 表示一个时间间隔. 先举一个小例子:(计算两个日期相差的天数) 代码如下: DateTime dt = DateTime.Now.ToShortDateString(yyyy ...
- iOS开发:创建真机调试证书 分类: ios相关 2015-04-10 10:22 149人阅读 评论(0) 收藏
关于苹果iOS开发,笔者也是从小白过来的,经历过各种困难和坑,其中就有关于开发证书,生产证书,in_house证书,add_Hoc证书申请过程中的问题,以及上架发布问题.今天就着重说一下关于针对于苹果 ...
随机推荐
- Java中的默认构造函数
java中如果在一个类中没有写明任何构造函数的,那么会存在一个无参的构造函数,如下: public class Children { private String name; private Stri ...
- 用js来实现银行家算法
Number.prototype.round = function (len) { var old = this; var a1 = Math.pow(10, len) * old; a1 = Mat ...
- EnumMap实现类
从名字上看出来,EnumMap是为枚举类服务的,它的key不能为null,在创建它的时候,必须要指定一个枚举类,如: EnumMap enumMap = new EnumMap(Season.clas ...
- C#语法基础
泛型 1.default(T)可以返回T类型的空值,因为你不知道T是值类型还是引用类型,所以别擅自用null 2.泛型约束 很多时候我们不希望使用者太过自由 我们希望他们在使用我们设计的泛型类型时 不 ...
- Mybatis-Generator自动生成Dao、Model、Mapping等相关映射文件(懒人版)
今天在学习mybatis生成相关的映射文件的时候,发现了往期的生成Dao.Model.Mapping等文章多数都是一样的,我也在学着重复造轮子,不过是懒人造的.本文旨在解决开发过程,简化配置文件的“手 ...
- C++ 静态数据成员和静态成员函数
一 静态数据成员: 1.静态数据成员的定义. 静态数据成员实际上是类域中的全局变量.所以,静态数据成员的定义(初始化)不应该被放在头文件中,因为这样做会引起重复定义这样的错误.即使加上#ifndef ...
- The valid characters are defined in RFC 7230 and RFC 3986
网上大都说什么发送格式与协议定义的不兼容,改tomcat版本或改编码之类的. 本人测试的时候换了个浏览器,不用IE就好了 如果坚持用ie,也有解决方式 @参考文章 成功的方法 在请求地址var url ...
- 使用Ansible部署etcd 3.2高可用集群
之前写过一篇手动搭建etcd 3.1集群的文章<etcd 3.1 高可用集群搭建>,最近要初始化一套新的环境,考虑用ansible自动化部署整套环境, 先从部署etcd 3.2集群开始. ...
- 批量去重URL地址并剔除打不开网址
#coding=utf-8 import os import httplib import socket dictlist ={}; def ReadHost(): hosts = []; obn = ...
- php自定义session存储路径
1.找到php.ini配置文件,找到session.save_path,修改如下: 其中2表示session存储的目录深度,也就是分目录,避免一个目录下文件太多,造成IO负担. session.sav ...