hihoCoder week 80
2016-01-12 17:49
357 查看
P1 : Magic Box
Time Limit:10000msCase Time Limit:1000ms
Memory Limit:256MB
Description
The circus clown Sunny has a magic box. When the circus is performing, Sunny puts some balls into the box one by one. The balls are in three colors: red(R), yellow(Y) and blue(B). Let Cr, Cy, Cb denote the numbersof red, yellow, blue balls in the box. Whenever the differences among Cr, Cy, Cb happen to be x, y, z, all balls in the box vanish. Given x, y, z and the sequence in which Sunny put the balls, you are to find what is the maximum number of balls in the box ever.
For example, let's assume x=1, y=2, z=3 and the sequence is RRYBRBRYBRY. After Sunny puts the first 7 balls, RRYBRBR, into the box, Cr, Cy, Cb are 4, 1, 2 respectively. The differences are exactly 1, 2, 3. (|Cr-Cy|=3,
|Cy-Cb|=1, |Cb-Cr|=2) Then all the 7 balls vanish. Finally there are 4 balls in the box, after Sunny puts the remaining balls. So the box contains 7 balls at most, after Sunny puts the first 7 balls and before they vanish.
Input
Line 1: x y zLine 2: the sequence consisting of only three characters 'R', 'Y' and 'B'.
For 30% data, the length of the sequence is no more than 200.
For 100% data, the length of the sequence is no more than 20,000, 0 <= x, y, z <= 20.
Output
The maximum number of balls in the box ever.
Hint
Another SampleSample Input | Sample Output |
0 0 0 RBYRRBY | 4 |
1 2 3 RRYBRBRYBRY
Sample Output
7
题意:向盒子里面按给定序列依次放球,R表示红色的球, Y表示黄色的球, B表示蓝色的球。分别用cr、cy、cb计数,记a = |cr - cy|, b = |cy - cb|, c = |cr - cb|,若a、b、c与x、y、z存在对应相等(不一定是a == x),那么盒子里面的球都会消失,问你盒子里最多可能存在多少个球。
模拟,维护最大值就可以了。
AC代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <map> #include <set> #include <vector> #include <string> #define INF 0x3f3f3f3f #define eps 1e-8 #define MAXN (20000+10) #define MAXM (200000+10) #define Ri(a) scanf("%d", &a) #define Rl(a) scanf("%lld", &a) #define Rf(a) scanf("%lf", &a) #define Rs(a) scanf("%s", a) #define Pi(a) printf("%d\n", (a)) #define Pf(a) printf("%.2lf\n", (a)) #define Pl(a) printf("%lld\n", (a)) #define Ps(a) printf("%s\n", (a)) #define W(a) while(a--) #define CLR(a, b) memset(a, (b), sizeof(a)) #define MOD 1000000007 #define LL long long #define lson o<<1, l, mid #define rson o<<1|1, mid+1, r #define ll o<<1 #define rr o<<1|1 #define PI acos(-1.0) using namespace std; char str[MAXN]; int x[3], xx[3]; bool judge(int a, int b, int c) { xx[0] = abs(a-b); xx[1] = abs(b-c); xx[2] = abs(a-c); sort(xx, xx+3); return x[0] == xx[0] && x[1] == xx[1] && x[2] == xx[2]; } int main() { while(scanf("%d%d%d", &x[0], &x[1], &x[2]) != EOF) { Rs(str); int len = strlen(str); int cr = 0, cy = 0, cb = 0; int ans = 0; int last = -1; sort(x, x+3); for(int i = 0; i < len; i++) { cr += str[i] == 'R'; cy += str[i] == 'Y'; cb += str[i] == 'B'; ans = max(ans, i - last); if(judge(cr, cy, cb)) { last = i; cr = cy = cb = 0; } } Pi(ans); } return 0; }
相关文章推荐
- runtime Method
- hdoj 4288 && Codeforces 85D Coder 【线段树】
- 如何查看安卓手机应用程序创建的数据库
- [练习]在一个数组中存300条记录,用3个线程统计求和。
- Android图片加载库Picasso源码分析
- Android应用性能测试
- 搭建vagrant环境
- 用vim打开c程序会出现乱码
- ajax 省市联动 代码
- oracle 锁表简单解锁
- Codeforces 612E Square Root of Permutation 【置换群】
- android之壁纸机制
- Linux 系统应用编程——网络编程(socket编程)
- 正则表达式符号
- git配置远程访问
- Echarts小练习
- inotify + rsync 打造文件实时同步
- Certificate、Provisioning Profile、App ID的介绍及其之间的关系
- Codeforces 612D The Union of k-Segments 【思维】
- 微信连wifi portal验证