【hihocoder】 Magic Box
题目1 : Magic Box
描述
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 z
Line 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 Sample
| Sample Input | Sample Output |
| 0 0 0 RBYRRBY |
4 |
- 样例输入
-
1 2 3
RRYBRBRYBRY - 样例输出
-
7
#include <string>
#include <iostream>
#include <cmath>
//#include <fstream>
using namespace std; int main(){ int r,y,b;
string s;
//ifstream cin("in.txt");
while(cin>>r>>y>>b>>s){ int ans = ,tmp=,cr,cy,cb;
cr = cy = cb = ;
for(int i = ; i < s.size(); ++i){
tmp++;
if(s[i] == 'R') cr++;
else if(s[i] == 'Y') cy++;
else cb++;
if(abs(cr - cy) != b)
continue;
if(abs(cr - cb) != y)
continue;
if(abs(cy - cb) != r)
continue;
if(tmp > ans)
ans = tmp;
tmp = ;
cr = cy = cb = ;
}
cout << ans << endl;
}
return ;
}
【hihocoder】 Magic Box的更多相关文章
- 【POJ2888】Magic Bracelet Burnside引理+欧拉函数+矩阵乘法
[POJ2888]Magic Bracelet 题意:一个长度为n的项链,有m种颜色的珠子,有k个限制(a,b)表示颜色为a的珠子和颜色为b的珠子不能相邻,求用m种珠子能串成的项链有多少种.如果一个项 ...
- 【CF878D】Magic Breeding bitset
[CF878D]Magic Breeding 题意:有k个物品,每个物品有n项属性值,第i个人的第j个属性值为aij,有q个操作: 1 x y 用x和y合成一个新的物品,新物品的编号是++k,新物品的 ...
- 【CF628D】Magic Numbers 数位DP
[CF628D]Magic Numbers 题意:求[a,b]中,偶数位的数字都是d,其余为数字都不是d,且能被m整除的数的个数(这里的偶数位是的是从高位往低位数的偶数位).$a,b<10^{2 ...
- 【POJ1442】【Treap】Black Box
Description Our Black Box represents a primitive database. It can save an integer array and has a sp ...
- 【poj1442】Black Box
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10890 Accepted: 4446 Description Our ...
- hihocoder 1135 : Magic Box
#1135 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. Whe ...
- 【优先队列】POJ1442-Black Box
[思路] 建立一个小堆和一个大堆.大堆用来存放第1..index-1大的数,其余数存放在大堆,小堆的堆顶元素便是我们要求出的第index大的数.每次插入一个A(n),必须保证大堆中数字数目不变,故先插 ...
- 【hihoCoder】1148:2月29日
问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...
- 【hihoCoder】1288 : Font Size
题目:http://hihocoder.com/problemset/problem/1288 手机屏幕大小为 W(宽) * H(长),一篇文章有N段,每段有ai个字,要求使得该文章占用的页数不超过P ...
随机推荐
- Map获取key值
有两种方法 public static void test4(){ Map<String, Object> map = new HashMap<>(); map.put(&qu ...
- 【个人阅读】软件工程M1/M2阶段总结
这次作业是好久以前布置的,由于学期末课程设计任务比较重,我在完善M2阶段的代码的同时又忙于数据库的实现和编译器的实现,一度感觉忙得透不过气来....到这些都基本完成的时候,会看自己以前的阅读心得,觉得 ...
- Linux内核分析——程序破解
1. 掌握NOP.JNE.JE.JMP.CMP汇编指令的机器码 NOP:NOP指令即“空指令”.执行到NOP指令时,CPU什么也不做,仅仅当做一个指令执行过去并继续执行NOP后面的一条指令.(机器码: ...
- 程序设计第三次作业---C++计算器雏形
Github链接:https://github.com/Wasdns/object-oriented 题目:程序设计第三次作业 程序设计第三次作业附加 我的程序设计第三次作业附加 代码规范 更新时间: ...
- github更新,发布地址,燃尽图,总结
github地址:https://github.com/Lingchaoyang 网盘发布地址:http://pan.baidu.com/s/1qXgHiyC 燃尽图: 团队得分(100分制): 杨灵 ...
- Sublime Text3前端必备插件
安装Package Control 在安装插件之前,需要让sublime安装Package Control.打开Sublime Text的控制台,快捷键ctrl + ~,在控制台中输入以下代码. im ...
- 博客用Markdown编辑器插入视频
要展示一些App的效果用或者更方便地展示工具的操作,可以使用视频. 以下有两种方式可以在博客中插入视频 第一种 此方法适用于插入来源优酷的视频或者你自己录制了视频上传到优酷,这种方法的好处是可以插入时 ...
- rem布局进阶
<script>!function(e){function t(a){if(i[a])return i[a].exports;var n=i[a]={exports:{},id:a,loa ...
- 查询数据SELECT 之单表查询
一.单表查询的语法与关键字的执行优先级""" # 单表查询# 单标查询完整与法:# select distinct(关键字,代表查询的意思,后面跟)字段1,字段2...( ...
- calico实现docker容器内部的网络链接
calico官网 https://www.projectcalico.org// calico介绍 http://www.sdnlab.com/17161.html calico网络 环境 系统 ...