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.

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <cstring>
 5 #include <string>
 6 #include <cmath>
 7 #include <queue>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <stack>
12 using namespace std;
13 #define INF 0x3f3f3f3f
14 #define N 100010
15 typedef long long LL;
16 char s[110];
17 int a[10], id[10];
18
19 int main() {
20     cin >> s;
21     int len = strlen(s);
22     memset(id, -1, sizeof(id));
23     for(int i = 0; i < len; i++) {
24         if(s[i] == ‘R‘) id[0] = i % 4;
25         if(s[i] == ‘B‘) id[1] = i % 4;
26         if(s[i] == ‘Y‘) id[2] = i % 4;
27         if(s[i] == ‘G‘) id[3] = i % 4;
28     }
29     for(int i = 0; i < 4; i++) {
30         if(id[i] == -1) {
31             id[i] = i;
32         }
33     }
34     for(int i = 0; i < len; i++) {
35         if(i % 4 == id[0] && s[i] != ‘R‘) a[0]++;
36         if(i % 4 == id[1] && s[i] != ‘B‘) a[1]++;
37         if(i % 4 == id[2] && s[i] != ‘Y‘) a[2]++;
38         if(i % 4 == id[3] && s[i] != ‘G‘) a[3]++;
39     }
40     for(int i = 0; i < 4; i++) printf("%d ", a[i]);
41     return 0;
42 }
时间: 2024-08-25 08:45:06

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

Codeforces 48C The Race 模拟题

题目链接:点击打开链接 题意: 给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油. 在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油. 开始有x升油 下面给出加油的记录. 问下一次加油在哪一站.若答案唯一输出具体哪站. 油箱容量无限 思路: 水模拟.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

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

CodeForces - 200DProgramming Language纯模拟

CodeForces - 200D Programming Language Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Recently, Valery have come across an entirely new programming language. Most of all the language attracted h

codeforces 614B(div.2) 模拟

模拟乘法 有毒的一题,各种细节..代码写得自己都不想看.. #include"cstdio" #include"queue" #include"cmath" #include"stack" #include"iostream" #include"algorithm" #include"cstring" #include"queue" #includ

CodeForces 1B. Spreadsheets(模拟)

题目链接:http://codeforces.com/problemset/problem/1/B B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input output standard output In the popular spreadsheets systems (for example, in Excel) the following

Codeforces #200(div.2) 模拟练习赛

A题: 题意:一行磁铁,同性相斥,找到这行磁铁可以分为多少块 思路:边读边计算,读到和上一次不一样的就加1(第一组数据特判) 手速题然而我没有把思路理清楚再写,比队友满了太多=_+. 代码: #include <set> #include <map> #include <cmath> #include <stack> #include <queue> #include <string> #include <vector>

Codeforces 704A Thor 队列模拟

题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡内存……详细看代码. #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<stdio.h> #include<stdlib.h&g

codeforces 589 G - Hiring(模拟?)

G - Hiring Time Limit:4000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 589G Description The head of human resources department decided to hire a new employee. He created a test exercise for candidat

Codeforces Gym 100496J(模拟乱搞,线段相交)

题意:给一个M*N的矩形区域,有M*N个方格,有些方格为空(可到达),有些非空(不可达).现A和B在博弈,他们任选两个不同的空格,站在各自的格子中央,A可以移动,但只能进行一次行方向或列向方移动,移动后仍然在格子中央.A如果移动到一个位置使得B看不见他,则A获胜.B看不见A的条件是存在一个非空格子与B到A的线段相切或相交.问,对于每个空格子,A站在上面,是否无论B在哪里,他都可以移动到一个安全位置. A可以选择不移动,题目保证至少有两个空格子,每次移动只能进行横向或竖向移动,不能都进行.空格子内