http://codeforces.com/problemset/problem/758/B

题意:给出一个字符串,每4个位置对应一个颜色,如果为‘!’的话,代表该灯泡是坏的,问最后每个颜色坏的灯泡的数目。

思路:题意实在挺难懂的(可能我到现在还没看懂)。看样例看了好久才看出来。例如最后一个样例“!GB!RG!Y!”:可以拆分成"!GB!”,"RG!Y","!",R只在第一个位置出现,说明R是在第一个位置的,以此类推,G是在第二个位置,B是在第三个位置,Y是在第四个位置。那么对应每个位置出现的“!”的数目,就是要求的对应颜色的值了。

首先先枚举一次串通过i%4找到每个颜色对应的位置,然后再枚举一遍串,如果对应位置出现“!”就对应颜色答案+1.

 #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
using namespace std;
#define INF 0x3f3f3f3f
#define N 100010
typedef long long LL;
char s[];
int a[], id[]; int main() {
cin >> s;
int len = strlen(s);
memset(id, -, sizeof(id));
for(int i = ; i < len; i++) {
if(s[i] == 'R') id[] = i % ;
if(s[i] == 'B') id[] = i % ;
if(s[i] == 'Y') id[] = i % ;
if(s[i] == 'G') id[] = i % ;
}
for(int i = ; i < ; i++) {
if(id[i] == -) {
id[i] = i;
}
}
for(int i = ; i < len; i++) {
if(i % == id[] && s[i] != 'R') a[]++;
if(i % == id[] && s[i] != 'B') a[]++;
if(i % == id[] && s[i] != 'Y') a[]++;
if(i % == id[] && s[i] != 'G') a[]++;
}
for(int i = ; i < ; i++) printf("%d ", a[i]);
return ;
}

Codeforces 758B:Blown Garland(模拟)的更多相关文章

  1. Codeforces 758B Blown Garland

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

  2. 758B Blown Garland

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

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

  4. 【codeforces 758B】Blown Garland

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

  5. Codeforces 392 B Blown Garland

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

  6. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  7. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  8. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  9. Codeforces 1108D - Diverse Garland - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...

随机推荐

  1. wpf 触摸屏 button 背景为null的 问题

    原文:wpf 触摸屏 button 背景为null的 问题 <!-- button样式--> <Style x:Key="myBtn" TargetType=&q ...

  2. Expression Blend学习5控件

    原文:Expression Blend学习5控件 Expression Blend ButtonStyle- TextButton 本章以TextButton为例,讲解如何最简单,最快速的制作一个专业 ...

  3. Android零基础入门第6节:配置优化SDK Manager,正式约会女神

    原文:Android零基础入门第6节:配置优化SDK Manager,正式约会女神 在前几期中总结分享了Android的前世今生.Android 系统架构和应用组件那些事.带你一起来聊一聊Androi ...

  4. C#命名约定

    推荐的标识命名风格 风格名称 描述 使用建议 示例 Pascal大小写 标识符中每个单词都首字母大写 用于类型名和成员名 CarDeck, DealersHand Camel大小写 除第一个单词以外, ...

  5. Android零基础入门第37节:初识ListView

    原文:Android零基础入门第37节:初识ListView 之前我们学习的一些UI组件都比较简单,但是在实际开发中,会经常遇见列表界面设计,如通讯录.电话列表.信息列表等.那么从本节开始来详细学习列 ...

  6. windows 2003 无法安装 .net4.0 windows服务

    错误: InstallUtil.InstallLog文件中的错误信息:   正在运行事务处理安装.   正在开始安装的“安装”阶段. 查看日志文件的内容以获得 D:\Debug\DataChang.e ...

  7. 为何只能在其关联的线程内启动timer?(Qt会检查一致性,否则就不执行)

    为何只能在其关联的线程内启动timer? 在QTimer源码分析(以Windows下实现为例) 一文中,我们谈到: QTimer的是通过QObject的timerEvent()实现的,开启和关闭定时器 ...

  8. Delphi 10.2 非官方补丁合集

    Delphi 10.2 非官方补丁合集http://blog.qdac.cc/?p=4485 FMXObject和TFORM的释放都变成异步了.虽然能保证是在主线程中释放,但是Windows部分的线程 ...

  9. CentOS7 无法使用yum命令,无法更新解决方法

    前言 设置网卡开机自动启动 设置国内dns服务器系统 修改CentOS-Base.repo中的地址 所参考的文章地址 前言 刚安装完的CentOS7的系统,发现无法使用yum命令进行更新,在更新的时候 ...

  10. Silverlight Virtualization Overview

    当ListBox使用StackPanel作为容器时,如果数据源包含大量数据时,每一条数据都要创建可视化的Item来承载数据,创建这些容器就需要消耗很多时间和内存,另外滚动也非常慢,因为需要计算所有这些 ...