#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 Sample
Sample Input Sample Output
0 0 0
RBYRRBY 4

样例输入

1 2 3
RRYBRBRYBRY

样例输出

7

C语言:

//cr,cy,cb三个差值等于x,y,z即可,无需考虑顺序
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int yxh(const void *p1,const void *p2)
{return *(int *)p1-*(int *)p2;
}
int main()
{int cr,cy,cb,a[3],b[3],i,max;char s[20001];scanf("%d%d%d",&a[0],&a[1],&a[2]);scanf("%s",&s);qsort(a,3,sizeof(int),yxh);//快排for(i=cr=cy=cb=max=0; s[i]!='\0'; i++){if(s[i]=='R'){cr++;}else if(s[i]=='Y'){cy++;}else if(s[i]=='B'){cb++;}b[0]=abs(cr-cy);b[1]=abs(cr-cb);b[2]=abs(cy-cb);qsort(b,3,sizeof(int),yxh);//快排if(a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]){if(max<cr+cy+cb){max=cr+cy+cb;}cr=cy=cb=0;}}if(max<cr+cy+cb){max=cr+cy+cb;}printf("%d",max);
}

#1135 : Magic Box相关推荐

  1. #1135 : Magic Box(枚举)

    #1135 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. Whe ...

  2. #hihocoder #1135 : Magic Box

    hihocoder #1135 : Magic Box 标签(空格分隔): hihocoder 1135 : Magic Box Description The circus clown Sunny ...

  3. hihoCoder #1135 : Magic Box

    题目地址:http://hihocoder.com/problemset/problem/1135 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus ...

  4. hihoCoder 1135 Magic Box 微软2016校园招聘在线笔试

    这一题写了好久也是醉了..直接模拟即可,注意difference是任意两个count的差,x,y,z不一定按照R,Y,B的顺序. #include<iostream> #include&l ...

  5. hihocoder 1135:Magic Box

    1135 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

  6. hihoCoder Magic Box

    题目 题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. Wh ...

  7. 【hihocoder】 Magic Box

    题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

  8. HDOJ 5155 Harry And Magic Box DP

    dp[i][j] 表示 长宽为i,j的矩形的可能的总数 dp[i][j+1] 可由 dp[i][j] 推过来,枚举dp[i][j]所保留的行数(1...i)即可 Harry And Magic Box ...

  9. Codeforces Round #143 (Div. 2)-D. Magic Box

    原题链接 D. Magic Box time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

最新文章

  1. debian6更新网卡驱动
  2. hdu 1496 Equations(技巧hash)
  3. office2007安装出现windows installer服务不能更新一个或多个受保护的windows文件
  4. java创建主键自增表_oracle创建表时设置自增主键
  5. Versions maven plugin 修改版本
  6. 最新建账年(over partition by)的研究
  7. python里写在文件的指定行_python文件操作如何写在指定的行
  8. JMeter如何和Charles进行接口测试
  9. Atitit.数据库存储引擎的原理与attilax 总结
  10. 百度快照劫持的解决方法
  11. 将文本中的各个单词的字母顺序翻转(Java)
  12. Esp32+Dht11+MQTT+Mysql实现测温数据传至数据库
  13. trufflle init 出现 unbox fail的情况
  14. 双向广搜(DBFS)
  15. 刷步数作弊方式解析,保护你微信运动里的那点隐私
  16. RK3568外设资源
  17. 常用校验方式以及优缺点(奇偶校验,CRC校验,校验和)
  18. android 解压缩zip包
  19. 【厚积薄发系列】C++项目总结17—《WHY C++ ? 王者归来》读后感
  20. 用python的tkinter做游戏(七)—— 双人射击游戏Demo(类的应用) 篇

热门文章

  1. 西北工业大学计算机二级考点,2020年3月全国计算机等级考试报名通知
  2. The Unarchiver 4.1.0版本在苹果电脑系统10.15.6上解压xcode.xip有问题
  3. 办公室装修风格都有哪些?
  4. Java,微信交流群
  5. 北大核心2020_清华和北大,可以同时上了
  6. Cordova 开发之安卓插件开发(二)
  7. webapi Message已拒绝为此请求授权。/Message
  8. 2021年茶艺师(高级)考试资料及茶艺师(高级)复审考试
  9. 统计一篇文章里不同单词的总数
  10. Android可信执行环境TEE最全介绍