微软2016校园招聘在线笔试之Magic Box
题目1 : 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 : x y z Line : the sequence consisting of only three characters 'R', 'Y' and 'B'. For % data, the length of the sequence is no more than . For % data, the length of the sequence is no more than ,, <= x, y, z <= .
输出
The maximum number of balls in the box ever.
提示
Another Sample
| Sample Input | Sample Output |
| 0 0 0 RBYRRBY | 4 |
样例输入
RRYBRBRYBRY
样例输出
第一次使用hihoCoder,不了解怎么使用,吃了大亏。贴一下我事后写的代码,未经验证。
solution:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x,y,z;
string s;
while (cin>>x>>y>>z>>s)
{
int cr = , cy = , cb = ;
int res = ;
int tmp;
for (int i = ;i < s.size();++i)
{
if(s[i] == 'R')
cr++;
else if(s[i] == 'Y')
cy++;
else
cb++;
if(abs(cr-cy) != z)
continue;
if(abs(cy-cb) != x)
continue;
if(abs(cb-cr) != y)
continue;
tmp = cr + cy + cb;
if(res < tmp)
{
res = tmp;
cr = cy = cb = ;
}
}
tmp = cr + cy + cb;
if(res < tmp)
res = tmp;
cout<<res<<endl;
}
return ;
}
微软2016校园招聘在线笔试之Magic Box的更多相关文章
- 微软2016校园招聘在线笔试-Professor Q's Software
题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new softw ...
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...
- 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]
传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...
- 微软2016校园招聘在线笔试 [Recruitment]
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A company plans to recruit some new employees. There are N ca ...
- 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场
题目3 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outin ...
- hihocoder 1288 : Font Size (微软2016校园招聘4月在线笔试)
hihocoder 1288 笔试第一道..wa了好几次,也是无语..hihocoder错了不会告诉你失败的时候的测试集,这样有时候就很烦.. 遍历所有的字体,从min(w,h)开始逐渐变小开始遍历. ...
- 微软2016校园招聘4月在线笔试 A FontSize
题目链接:http://hihocoder.com/problemset/problem/1288 分析:题目中所求的是最大的FontSize(记为S),其应该满足P*[W/S]*[H/S] > ...
- 微软2016校园招聘4月在线笔试 ABC
题目链接:http://hihocoder.com/contest/mstest2016april1/problems 第一题:输入N,P,W,H,代表有N段文字,每段有ai个字,每行有⌊W/S⌋个字 ...
- 微软2016校园招聘4月在线笔试 hihocoder 1289 403 Forbidden
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 Little Hi runs a web server. Sometimes he has to deny acces ...
随机推荐
- Array(数组)对象-->unshift() 方法
1.定义和用法 unshift() 方法可向数组的开头添加一个或更多元素,并返回新的长度. 语法: array.unshift(item1,item2, ..., itemX) 参数:item1,it ...
- 一、Python3.8的安装
一:什么是Python解释器 解释器(英语:Interpreter),又译为直译器,是一种电脑程序能够把高级编程语言一行一行直接转译运行. 解释器不会一次把整个程序转译出来,只像一位“中间人”,每次运 ...
- python3(二十四) subClas
""" 继承的多态 """ __author__ = 'shaozhiqi' # -----------------父类---------- ...
- input相关
input相关 在ios中输入英文首字母默认大写取消方法 <input autocapitalize="off" autocorrect="off" /& ...
- 远程登录redis
没想到吧,我居然已经摸到了redis. 远程登录redis redis-cli -h 127.0.0.1 -p 6379 ip地址和端口记得换成自己的
- 从零开始学AB测试:基础篇
什么是AB测试? 通俗点理解,AB测试就是比较两个东西好坏的一套方法,这种A和B的比较在我们的生活和人生中非常常见,所以不难理解.具体到AB测试这个概念,它和我们比较哪个梨更大.比较哪个美女更漂亮.比 ...
- CVE-2018-12613 的一些思考
复现 CVE-2018-12613 的一些思考,关于文件包含路径的问题 漏洞 /index.php 第 55 行 $target_blacklist = array ( 'import.php', ' ...
- 《Spring In Action》阅读笔记之核心概念
DI 依赖注入:在xml中配置的bean之间的依赖关系就是依赖注入 AOP 面向切面编程:如在xml中定义某个方法为切点,然后配置在该切点(该方法)调用前后需要调用的方法,从而简化了代码并解耦. Sp ...
- java 一维数组的总结笔记
数组 1. 一位数组的声明方式 type[] array Name 或 type arrayName[];(推荐使用第二种) 错误的声明方式 //int[5] intErrorArray;错误的 // ...
- JUC并发编程基石AQS之主流程源码解析
前言 由于AQS的源码太过凝练,而且有很多分支比如取消排队.等待条件等,如果把所有的分支在一篇文章的写完可能会看懵,所以这篇文章主要是从正常流程先走一遍,重点不在取消排队等分支,之后会专门写一篇取消排 ...