hihocoder 1135 : Magic Box
2015-06-06 13:58
330 查看
#1135 : Magic Box
时间限制:10000ms单点时限:1000ms
内存限制:256MB
描述
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 numbers of 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.
输入
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.
输出
The maximum number of balls in the box ever.提示
Another SampleSample Input | Sample Output |
0 0 0 RBYRRBY | 4 |
1 2 3 RRYBRBRYBRY
样例输出
7
/** 题意:给一串有Y B R 组成的字符串,然后如果他们之间的个数差 等与X Y Z 那就消除现在的 字符串,直到字符串结束,看容器中最多有多少个字符 刚开始题意理解错了 他们之间 的随意差值都等于 X Y Z 都行,并且没有重用的;然后就。。。。。 做法:枚举 **/ #include <iostream> #include <string.h> #include <stdio.h> #include <cmath> #include <algorithm> #include <queue> #define maxn 200100 using namespace std; int num[4]; char ch[maxn]; int a,b,c; bool solve() { int ax,ay,bx,by; bool flag1 = false; bool flag2 = false; bool flag3 = false; for(int i=0; i<3; i++) { for(int j=i+1; j<3; j++) { if(abs(num[i] - num[j]) == a) { ax = i; ay = j; flag1 = true; break; } } } for(int i=0; i<3; i++) { for(int j=i+1; j<3; j++) { if(abs(num[i] - num[j]) == b) { if(ax == i && ay == j) continue; bx = i; by = j; flag2 = true; break; } } } for(int i=0; i<3; i++) { for(int j=i+1; j<3; j++) { if(abs(num[i] - num[j]) == c) { if(i == ax &&j == ay) continue; if(i == bx && j == by) continue; flag3 = true; break; } } } if(flag1 && flag2 && flag3) return true; return false; } int main() { //#ifndef ONLINE_JUDGE // freopen("in.txt","r",stdin); //#endif // ONLINE_JUDGE while(~scanf("%d %d %d",&a,&b,&c)) { scanf("%s",ch); memset(num,0,sizeof(num)); int len = strlen(ch); int ans = 0; for(int i=0; i<len; i++) { if(ch[i] == 'R') num[0] ++; else if(ch[i] == 'B') num[1] ++; else num[2]++; ans = max(ans,num[0] + num[1] + num[2]); if(solve()) { // cout<<num[0] <<" "<<num[1] <<" "<<num[2] <<endl; memset(num,0,sizeof(num)); } } printf("%d\n",ans); } return 0; }
相关文章推荐
- C 文件操作库函数总结
- cmake学习(二)常用变量和常用环境变量
- Android Stdio常见问题解决
- 清除keil编译中间文件的脚本
- CMake 手册详解(二十二)
- 【Java】利用ant插件压缩文件夹及其所有子文件与子文件夹
- 移动端页面侧边导航滑入效果
- SAE上部署
- 如何快速开发网站?
- 设计模式C++实现(16)——状态模式
- 探索:移动互联网如何颠覆医疗
- BZOJ 1692: [Usaco2007 Dec]队列变换( 贪心 )
- CAAnimation 类基本学习
- Web前端优化最佳实践
- OC基础学习——如何解析plist文件和数据的归档和解档与json数据的解析
- SQL Server 批量插入数据的两种方法
- linux之vim设置行号
- 使用叉积判断两条直线是否相交
- Linux学习笔记(06-06)Ubuntu用户密码正确但登陆无效解决方法
- 读LockSupport源码