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. Angular路由守卫 canDeactivate

    目的 离开页面时,做出逻辑判断 以ng-alain的项目为基础做演示 效果如图: 关键代码 定义一个CanDeactivateGuardService export class CanDeactiva ...

  2. 合并 && 还原属性链

    效果 原数据 { "id": 10, "text": { "title": "title", "content ...

  3. Ogre 1.7.0,VS2005编译全过程傻瓜式教程

    最近下了最新版Ogre 1.7.0,从下载到最后编译运行成功Ogre自带的Sample花了将近一下午时间. 网上有很多编译Ogre的教程,这里整理我看过的教程,加上自己的经验再详细总结一遍. 第一步: ...

  4. Delphi调试activex

    以前好多次遇到了activex无法调试的问题,一直没搞清楚原因,最近终于搞清楚了,原来是IE由单线程变成了多线程. 下面就说说调试activex的方法 一.简单的方式,这种方式只适用于浏览器为单线程的 ...

  5. Win10《芒果TV》春季商店版更新v3.3.0:全新视觉蜕变&支持快男直播

    在微软发布Win10创意者更新正式版前夕,Win10版<芒果TV>迅速更新至v3.3.0,主要是全新升级视觉交互,新增大咖快男个人直播,全面优化底层架构,启动大提速. Win10版< ...

  6. web-dev-server配置

    webpack-dev-server是一个小型的Node.js Express服务器,它使用webpack-dev-middleware来服务于webpack的包,除此自外,它还有一个通过Sock.j ...

  7. C# 设置IP地址及设置自动获取IP

    原文:C# 设置IP地址及设置自动获取IP </pre><pre name="code" class="csharp">1.添加引用&q ...

  8. C# WebRequest POST上传数据

    WebRequest request = WebRequest.Create("http://www.cnsos.net"); // Set the Method property ...

  9. java8计算时间差

    示例1:计算指定时间单位的时间差 import java.time.Instant;import java.time.LocalDateTime;import java.time.temporal.C ...

  10. Hadoop集群(第1期)CentOS安装配置

    1.准备安装 1.1 系统简介 CentOS 是什么? CentOS是一个基于Red Hat 企业级 Linux 提供的可自由使用的源代码企业级的 Linux 发行版本.每个版本的 CentOS 都会 ...