#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
/**
题意:给一串有Y B R 组成的字符串,然后如果他们之间的个数差 等与X Y Z 那就消除现在的
字符串,直到字符串结束,看容器中最多有多少个字符 刚开始题意理解错了 他们之间
的随意差值都等于 X Y Z 都行,并且没有重用的;然后就。。。。。
做法:枚举
**/
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>
#define maxn 200100
using namespace std;
int num[];
char ch[maxn];
int a,b,c;
bool solve()
{
int ax,ay,bx,by;
bool flag1 = false;
bool flag2 = false;
bool flag3 = false;
for(int i=; i<; i++)
{
for(int j=i+; j<; j++)
{
if(abs(num[i] - num[j]) == a)
{
ax = i;
ay = j;
flag1 = true;
break;
}
}
}
for(int i=; i<; i++)
{
for(int j=i+; j<; j++)
{
if(abs(num[i] - num[j]) == b)
{
if(ax == i && ay == j) continue;
bx = i;
by = j;
flag2 = true;
break;
}
}
}
for(int i=; i<; i++)
{
for(int j=i+; j<; j++)
{
if(abs(num[i] - num[j]) == c)
{
if(i == ax &&j == ay) continue;
if(i == bx && j == by) continue;
flag3 = true;
break;
}
}
}
if(flag1 && flag2 && flag3) return true;
return false;
}
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
//#endif // ONLINE_JUDGE
while(~scanf("%d %d %d",&a,&b,&c))
{
scanf("%s",ch);
memset(num,,sizeof(num));
int len = strlen(ch);
int ans = ;
for(int i=; i<len; i++)
{
if(ch[i] == 'R') num[] ++;
else if(ch[i] == 'B') num[] ++;
else num[]++;
ans = max(ans,num[] + num[] + num[]);
if(solve())
{
// cout<<num[0] <<" "<<num[1] <<" "<<num[2] <<endl;
memset(num,,sizeof(num));
}
}
printf("%d\n",ans);
}
return ;
}

hihocoder 1135 : Magic Box的更多相关文章

  1. 【hihocoder】 Magic Box

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

  2. 微软2016校园招聘在线笔试之Magic Box

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

  3. hihoCoder#1135

    刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正. 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The c ...

  4. BestCoder Round #25 1002 Harry And Magic Box [dp]

    传送门 Harry And Magic Box Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  5. hihoCoder题目之Magic Box

    #include <iostream> #include <cmath> #include <cstdio> using namespace std; void s ...

  6. D. Magic Box(几何)

    One day Vasya was going home when he saw a box lying on the road. The box can be represented as a re ...

  7. HDU 5155 Harry And Magic Box --DP

    题意:nxm的棋盘,要求每行每列至少放一个棋子的方法数. 解法:首先可以明确是DP,这种行和列的DP很多时候都要一行一行的推过去,即至少枚举此行和前一行. dp[i][j]表示前 i 行有 j 列都有 ...

  8. [HDOJ 5155] Harry And Magic Box

    题目链接:HDOJ - 5155 题目大意 有一个 n * m 的棋盘,已知每行每列都至少有一个棋子,求可能有多少种不同的棋子分布情况.答案对一个大素数取模. 题目分析 算法1: 使用容斥原理与递推. ...

  9. 【HDOJ】5155 Harry And Magic Box

    DP.dp[i][j]可以表示i行j列满足要求的组合个数,考虑dp[i-1][k]满足条件,那么第i行的那k列可以为任意排列(2^k),其余的j-k列必须全为1,因此dp[i][j] += dp[i- ...

随机推荐

  1. 洛谷 P4964 绫小路的特别考试 解题报告

    P4964 绫小路的特别考试 题目背景 这世界上「胜利」便是一切.无关乎过程. 要付出多少牺牲都无所谓.只要最后我「胜出」那就行了. 题目描述 一场新的特别考试来临了,这次的考试内容是(wan e d ...

  2. 玩(lay) 解题报告

    玩(lay) 题目名称 你的昆特牌打的太好啦!不一会你就 \(\tt{AK}\) 了 \(\tt{NOGP}\),只能无聊地堆牌玩! 题目描述 你有一些矩形卡牌,每次你会作如下三个操作: 紧挨着最后一 ...

  3. 洛谷 P3119 [USACO15JAN]草鉴定Grass Cownoisseur 解题报告

    P3119 [USACO15JAN]草鉴定Grass Cownoisseur 题目描述 约翰有\(n\)块草场,编号1到\(n\),这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可 ...

  4. NOIP2015Day2T3运输计划(二分+树上差分)

    做了这么多NOIPTG的题,这是唯一 一道一眼秒的T3(有时候T2还不会做QAQ)... 题目大意就不说了QWQ 思路大概是:啊最大值最小化,来个二分.检验mid的话,显然就是用最长路径减去所有边权& ...

  5. YBT 5.1 区间类动态规划

    题解在代码中 石子合并[loj 10147] /* dp[i][j]=max or min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]) i<=k& ...

  6. 阿里云配置redis

    一.redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sor ...

  7. train loss与test loss结果分析(接利用caffe的solverstate断点训练)

    train loss 不断下降,test loss不断下降,说明网络仍在学习; train loss 不断下降,test loss趋于不变,说明网络过拟合; train loss 趋于不变,test ...

  8. Codeforces Round #337 (Div. 2)B

    B. Vika and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. su对环境变量做了什么

    服务器是ubuntu12.04 用一个账户app,使用su - app得到的环境变量和直接ssh登录的环境变量不同. 导致su - app,无法执行ifconfig su - app 的环境变量 /u ...

  10. JQuery源码实现

    技术提高篇--- 推荐--- 动脑学院--- http://www.toutiao.com/a6368703139592569089/