hihocoder 1135 : Magic Box
#1135 : Magic Box
描述
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的更多相关文章
- 【hihocoder】 Magic Box
题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...
- 微软2016校园招聘在线笔试之Magic Box
题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...
- hihoCoder#1135
刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正. 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The c ...
- 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/ ...
- hihoCoder题目之Magic Box
#include <iostream> #include <cmath> #include <cstdio> using namespace std; void s ...
- 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 ...
- HDU 5155 Harry And Magic Box --DP
题意:nxm的棋盘,要求每行每列至少放一个棋子的方法数. 解法:首先可以明确是DP,这种行和列的DP很多时候都要一行一行的推过去,即至少枚举此行和前一行. dp[i][j]表示前 i 行有 j 列都有 ...
- [HDOJ 5155] Harry And Magic Box
题目链接:HDOJ - 5155 题目大意 有一个 n * m 的棋盘,已知每行每列都至少有一个棋子,求可能有多少种不同的棋子分布情况.答案对一个大素数取模. 题目分析 算法1: 使用容斥原理与递推. ...
- 【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- ...
随机推荐
- BZOJ1026:[SCOI2009]windy数——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1026 Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2 ...
- BZOJ3343 & 洛谷2801:教主的魔法——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=3343 https://www.luogu.org/problemnew/show/2801 题目描述 ...
- bzoj3680: 吊打XXX(模拟退火)
题目要求 最小(dis表示绳结到点i的距离),就是个广义费马点的题,模拟退火裸题QAQ 模拟退火就是优化后的爬山算法,一开始先随机一个平均点,接下来如果随机到的点比当前点劣,温度比较高的话也有几率跳过 ...
- SGU - 282
SGU - 282 题解 题意: 本质不同的集合:不存在两个方案重新编号之后对应的边集相同(对于所有x,y,,(x,y)边颜色都相同). (1≤ N≤ 53, 1≤ M≤ 1000) 对P取模 本质不 ...
- BUG:Open quote is expected for attribute "{1}" associated with an element type "id".
BUG原因:Mybatis的xml文件中id缺少双引号: 正确的应该是:
- Unresolved import *** (models) error on Eclipse
Eclipse version: Oxygen.2 Release (4.7.2) Python version: 3.6 问题:系统提示:from django.db import models 语 ...
- 理解LINUX LOAD AVERAGE的误区
一直不解,为什么io占用较高时,系统负载也会变高,偶遇此文,终解吾惑. uptime和top等命令都可以看到load average指标,从左至右三个数字分别表示1分钟.5分钟.15分钟的load a ...
- win下删除oracle
关掉oralce服务. 具体方式有两种: 1.命令行下使用命令关闭服务:net stop OracleServiceORCL ,ORCL是我的实例名字,换成你的) 2.运行services.msc到系 ...
- 数学:拓展BSGS
当C不是素数的时候,之前介绍的BSGS就行不通了,需要用到拓展BSGS算法 方法转自https://blog.csdn.net/zzkksunboy/article/details/73162229 ...
- 通过.NET客户端异步调用Web API(C#)
在学习Web API的基础课程 Calling a Web API From a .NET Client (C#) 中,作者介绍了如何客户端调用WEB API,并给了示例代码. 但是,那些代码并不是非 ...