#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 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

题意:

一个字符串三种字母代表三种颜色,按顺序从头到尾输入。给你三个数字x,y,z,倘若三种颜色差恰好等于x,y,z那么气球将爆炸,然后继续输入未输入完成的,知道输入完或者再次爆炸,求爆炸区段里最大的一段。

思路:

a数组存放xyz,b数组存放差,b[0]=R-Y,b[1]=R-B,b[2]=Y-B;然后加一个判断看是否爆炸

代码:

/*
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#define INF 1e9
const int maxn=5000+100;
typedef long long ll;
using namespace std;
bool ok(int a[],int b[]){
    int c[3];
    memset(c,0,sizeof(c));
    for(int i=0;i<3;i++) c[i]=abs(b[i]);
    sort(c,c+3);
    for(int i=0;i<3;i++)
        if(a[i]!=c[i])
        return false;
    return true;
}
int main(){
    int a[3];
    int b[3];
    string s;
    while(cin>>a[0]>>a[1]>>a[2]){
        sort(a,a+3);
        cin>>s;
        int len=s.length();
        int ans=0;
        int maxx=0;
        memset(b,0,sizeof(b));
        for(int i=0;i<len;i++){
            if(s[i]=='R'){
                b[0]++;
                b[1]++;
            }
            else if(s[i]=='Y'){
                b[0]--;
                b[2]++;
            }
            else if(s[i]=='B'){
                b[1]--;
                b[2]--;
            }
            ans++;
            if(ok(a,b)){
                if(maxx<ans)
                    maxx=ans;
                ans=0;
                memset(b,0,sizeof(b));
            }

}
        if(maxx<ans) maxx=ans;
        cout<<maxx<<endl;
    }
    return 0;
}

#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. 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 ...

  7. hdu 5155 Harry And Magic Box(DP)

    题目链接:hdu 5155 Harry And Magic Box dp[i][j]表示i∗j的矩阵方案数,dp[i][j]从dp[i−k][j−1]中转移,枚举前面j-1列中k行为空,那么这些行在第 ...

  8. HDU5155 Harry And Magic Box

    Harry And Magic Box 传送门1 传送门2 One day, Harry got a magical box. The box is made of n*m grids. There ...

  9. hihoCoder Magic Box

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

最新文章

  1. matlab cam orbit,如何在MATLAB中平滑旋转3D绘图?
  2. 【树莓派】树莓派CSI摄像头安装及测试方法
  3. Thymeleaf——使用模板动态生成JavaScript脚本文件
  4. 深入互联网广告中的出价模式(中) — 智能出价模式
  5. extjs插件开发上传下载文件简单案例
  6. codeforces1485 F. Copy or Prefix Sum(dp)
  7. 使用nodejs和art-template模板引擎实现apache的部分功能
  8. java两个对象属性比较
  9. 华三刀片服务器如何安装系统,刀片服务器及其操作系统的安装方法及系统专利_专利查询 - 天眼查...
  10. python求最大值最小值求和_python3.2求和与最值
  11. 【博客管理】博客资源汇总【置顶】
  12. python 如何判断字典存在key
  13. Android AlertDialog的一切
  14. 算法设计与分析第一章习题解答与学习指导(第2版)屈婉婷 刘田 张立昂 王捍贫编著 清华大学出版社
  15. 实验一计算机基础和网络知识竞赛,邵阳市计算机基础知识竞赛试题
  16. 打开统计年鉴html,南京统计年鉴2018(HTML)
  17. 不用格式化,5条命令,让Macbook支持ntfs硬盘读写
  18. 问卷调查网站制作-前后端开发
  19. 项目启动失败解决方法
  20. 计算机组成原理实验一:运算器组成的实验

热门文章

  1. jvm探秘五:Class类文件结构之属性表
  2. js 正则表达式禁止输入框输入特殊字符遇到的坑以及解决方案
  3. 邢不行 | Python量化 + 数字货币 + 轮动 = 4年1000倍【附代码】
  4. 错误代码 0x80070035 找不到网络路径 终极解决办法
  5. (C语言)有一篇文章,共有3行文字,每行有80个字符。要求统计出其中英文大写字母,小写字母,数字,空格,其他字符的个数
  6. CVX文档(Release 2.2)(自翻中文)
  7. 【Vue】实战项目:电商后台管理系统(Element-UI)(一)前后端搭建 - 登录界面 - 主页界面
  8. Transaction rollback
  9. icloud无法注销,icloud服务中keyChain钥匙串无法关闭问题的解决。
  10. javafx设置背景图片