#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. BZOJ1591 & 洛谷2924:[USACO2008 DEC]Largest Fence 最大的围栏——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1591 https://www.luogu.org/problemnew/show/P2924#sub ...

  2. bzoj1211: [HNOI2004]树的计数(purfer编码)

    BZOJ1005的弱化版,不想写高精度就可以写这题嘿嘿嘿 purfer编码如何生成?每次将字典序最小的叶子节点删去并将其相连的点加入序列中,直到树上剩下两个节点,所以一棵有n个节点的树purfer编码 ...

  3. HashMap & SparseArray & ArrayMap 简单说明

    HashMap 使用有限一维拉链数组存储结构,鉴于所用Entry结构{key, value, nextExtry},Key的hash值用于取余获得所属的数组行下标,通过链表方式顺序存放所有余数相同的各 ...

  4. 【树形DP】【P1364】医院放置

    传送门 Description 设有一棵二叉树,如图: 其中,圈中的数字表示结点中居民的人口.圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接 ...

  5. Parcelable序列化对象

    一.序列化的目的 永久性保存对象,保存对象的字节序列到本地文件中: 通过序列化对象在网络中传递对象: 通过序列化在进程间传递对象; 在Intent中进行传递复杂自定义类对象时,需要实现Parcelab ...

  6. 轮廓算法的结果验证工具/How to validate the outline output

    因为轮廓算法的结果通过直接观察输出很难判断结果的正确性. 但是如果把输入和输出同时绘制出来,用眼睛判别则相对简单许多. 输入建筑的文件内容格式为,粗体格式为建筑高度: 10 110 5020 60 7 ...

  7. 文件上传文件的权限--lnmp 环境配置,尤其整个项目复制过来动~~~

    site_upload  需要是自己才建立动才会是root  root  所有者:---不是root :  root   上传不了文件,不是  777 就都可以上传的,也要看看是谁建立的文件夹: 打包 ...

  8. Sublime Text 配置python文件

    每次配置Sublime Text的都是好一顿搜索配置信息,今天特地把自己电脑上配置好的信息保存下来,方便以后使用. 用到了 AutoPEP8.Anaconda.SublimeCodeIntel.Sub ...

  9. window10系统下使用python版本实现mysql查询

    参考文档: 兔大侠整理的MySQL-Python(MySQLdb)封装类 Python安装模块出错(ImportError: No module named setuptools)解决方法 环境 (w ...

  10. springboot-用logback将日志文件按等级保存到不同文件

    springboot-用logback将日志文件按等级保存到不同文件 案例: 例如项目基本包名为com.xxx,将该包下的所有日志按debug.info.warn.error等级分别保存到D:/log ...