#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. AOJ.综合训练.2016-12-8

    提示:多个题目的代码采用了C ++的写法,对应编译器选择G ++,请不要直接复制代码. 下周实验考试,GOOD LUCK! 感谢汪神提供E题C语言代码 所有题目已更新为C语言写法 所有题目已更新为C语 ...

  2. HDOJ.1009 FatMouse' Trade (贪心)

    FatMouse' Trade 点我挑战题目 题意分析 每组数据,给出有的猫粮m与房间数n,接着有n行,分别是这个房间存放的食物和所需要的猫粮.求这组数据能保证的最大的食物是多少? (可以不完全保证这 ...

  3. [zhuan]arm中的汇编指令

    http://blog.csdn.net/qqliyunpeng/article/details/45116615 一. 带点的(一般都是ARM GNU伪汇编指令)   1. ".text& ...

  4. javascript实用例子

    js学习笔记,别错过!很有用的. /////////////////////////////////////////////////////////////////////////////////// ...

  5. Better Linux Disk Caching & Performance with vm.dirty_ratio & vm.dirty_background_ratio

    In previous posts on vm.swappiness and using RAM disks we talked about how the memory on a Linux gue ...

  6. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

  7. JQuery学习五

    获取样式attr("myclass")移除样式removeClass("myclass")增加样式addClass("myclass")to ...

  8. 南阳ACM 题目71:独木舟上的旅行 Java版

    独木舟上的旅行 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 进行一次独木舟的旅行活动,独木舟可以在港口租到,并且之间没有区别.一条独木舟最多只能乘坐两个人,且乘客的总 ...

  9. NOIP2006 数列

    codevs 1141 数列 http://codevs.cn/problem/1141/ 2006年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB     题目描述  ...

  10. 【CodeForces】835D Palindromic characteristics

    [题意]给你一个串,让你求出k阶回文子串有多少个.k从1到n.k阶子串的定义是:子串本身是回文串,而且它的左半部分也是回文串. [算法]区间DP [题解]涉及回文问题的区间DP都可以用类似的写法,就是 ...