Codeforces 758B:Blown Garland(模拟)
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(模拟)的更多相关文章
- Codeforces 758B Blown Garland
题目链接:http://codeforces.com/contest/758/problem/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
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 392 B Blown Garland
题意:输入是由连续的RYGB和字符!组成的字符串,R代表红灯,Y代表黄灯,G代表绿灯,B代表蓝灯.简而言之,就是给定的字符串保证了下标对4取余相同的灯颜色都相同,但是有的地方为‘!’代表这个灯坏了,然 ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 1108D - Diverse Garland - [简单DP]
题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...
随机推荐
- x:key和x:name
x:Key用在xaml Resources,ResourceDictionary需要key来访问x:Name用在ResourceDictionary以外任何地方,可以使用x:Name在code-beh ...
- XF内容视图和框架
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http:/ ...
- 反编译 war 包成传统项目的方法
需求 项目老大让外包做了官网,不甚满意,想自己搞搞,遂叫我反编译他们发过来的 war 包. 方法 第一步:解压 war 包其实就是 zip 压缩包,用 zip 解压. 第二步:反编译 查看 war 包 ...
- WPF 流打印
原文:WPF 流打印 PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { Syst ...
- vs2010 编译release没问题debug编译不通过
------ 已启动全部重新生成: 项目: VM661JTcpDLL, 配置: Debug Win32 ------生成启动时间为 2018-12-29 14:07:20.项目文件包含 ToolsVe ...
- WP8.1使用HttpClient类
Uri uri = new Uri("http://www.cnsos.net/weburl/index.htm", UriKind.Absolute); HttpClient m ...
- 仿win7窗体自动顶部最大化左侧右侧半屏效果(改写nativeEvent,使用AdjustWindowRectEx)
#include "HMainWindow.h" #include <QApplication> #ifdef Q_OS_WIN #include <qt_win ...
- 淘宝开源Key/Value结构数据存储系统Tair技术剖析
摘要: Tair的功能 Tair是一个Key/Value结构数据的解决方案,它默认支持基于内存和文件的两种存储方式,分别和我们通常所说的缓存和持久化存储对应. Tair除了普通Key/Value系统提 ...
- LFTP 4.6.2 发布,命令行 FTP 工具。这个东东可以用来做插件
直击现场 这个东东可以用来做插件 LFTP 4.6.2 发布,新增特征如下: * new command "edit" instead of the edit alias.* n ...
- Hibernate注解(二):关联关系映射注解
关联关系映射注解以下项目均在之前相应代码的基础上进行的修改.这些项目均需要做的是: 删除映射文件 在hibernate.cfg.xml中注册实体类 注解的重要位置在实体类中关联属性上.这里是关联 ...