2016微软笔试题
来源:互联网 发布:windows me序列号 编辑:程序博客网 时间:2024/05/18 02:25
题目1 : Magic Box
- 样例输入
1 2 3RRYBRBRYBRY
- 样例输出
7
描述
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
RBYRRBY 4
#include<iostream>#include<string>#include<cmath>#include<algorithm>using namespace std;fdbool vanish(int cr,int cy,int cb,int x[]){int D[3];D[0]=abs(cr-cy);D[1]=abs(cy-cb);D[2]=abs(cr-cb);sort(D,D+3);if((D[0]==x[0])&&(D[1]==x[1])&&(D[2]==x[2]))return 1;elsereturn 0;}int main(){int x[3];int cr,cy,cb;cr=0;cy=0;cb=0;string str;int len,i;int result=0;cin>>x[0]>>x[1]>>x[2];sort(x,x+3);cin>>str;len=str.length();for(i=0;i<len;i++){switch(str[i]){case 'R':{cr++;break;}case 'Y':{cy++;break;}case 'B':{cb++;break;}default:break;}if(vanish(cr,cy,cb,x)){result=max(result,cr+cy+cb);//result=(result>(cr+cy+cb))?result:(cr+cy+cb);cr=0;cy=0;cb=0;}}result=max(result,cr+cy+cb); cout<<result<<endl;return 0;}
- 2016微软笔试题
- 微软2016校招笔试题
- 微软2016春招笔试题1
- 2016微软校招笔试题
- [转载] 微软笔试题
- 微软笔试题(zz)
- 微软笔试题3
- 微软笔试题4
- 微软笔试题一
- 微软笔试题
- 微软笔试题 汇总
- 2011微软笔试题
- 微软笔试题
- 微软笔试题
- 2011微软笔试题
- 微软笔试题
- 微软笔试题
- 微软笔试题:
- JS前台加密,java后台解密实现
- 获取文件CRC和MD5
- memset函数初始化数组简单解释,忽略复杂的原理~~~
- JAVA总结的实用小常识
- PAT (Basic Level) Practise (中文)
- 2016微软笔试题
- DSD音频基本原理
- 【dubbo】-003 dubbo中 ZooKeeper的安装
- STM32实现任意角度移相全桥PWM
- ASP.NET MVC 数据验证
- C++学习之引用
- 微软实习招聘题目: recruiment
- 2015阿里巴巴实习生笔试题-不懂的问题
- 【dubbo】-004ZooKeeper+Dubbo架构搭建