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- ...
随机推荐
- bzoj3224: Tyvj 1728 普通平衡树(打个splay暖暖手)
(其实今天好热啊? 题目大意:插入,删除,k小,前驱后继,数的排名. splay和treap裸题...过几天补个treap的 splay: #include<iostream> #incl ...
- [转载]系统管理:update-alternatives
http://blog.csdn.net/dbigbear/article/details/4398961 好吧,其实博主也是转载的. update-alternatives --display | ...
- bzoj 4695 最假女选手 吉利线段树
最假女选手 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 480 Solved: 118[Submit][Status][Discuss] Desc ...
- Http字段含义
转载自:http://blog.csdn.net/sand_ant/article/details/10503579 一.request请求Header简介 Accept:--客户机支持的类型 Acc ...
- Chrome控制台报错个人总结(不定时更新)
最近开始使用Chrome控制台检测代码错误,对于经常碰到的报错做一个汇总,免得每次遇到都要重新想一遍策略,错误原因,重复劳动,浪费时间. 由于不是每个错误都能碰到,以下仅列出个人写代码时经常碰到的报错 ...
- DataGridView导出到Word
#region 使用Interop.Word.dll将DataGridView导出到Word /// <summary> /// 使用Interop.Word.dll将DataGridVi ...
- spoj COT2 - Count on a tree II
COT2 - Count on a tree II http://www.spoj.com/problems/COT2/ #tree You are given a tree with N nodes ...
- bzoj 1878: [SDOI2009]HH的项链 ——树状数组+ 差分
Description HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步 完后,他都会随意取出一 段贝壳,思考它们所表达的含义.HH不断地收集新的贝壳,因此他的项链变得 ...
- Piggy-Bank(多重背包+一维和二维通过方式)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 题面: Problem Description Before ACM can do anythi ...
- bzoj 1912 tree_dp
这道题我们加一条路可以减少的代价为这条路两端点到lca的路径的长度,相当于一条链,那么如果加了两条链的话,这两条链重复的部分还是要走两遍,反而对答案没有了贡献(其实这个可以由任意两条链都可以看成两条不 ...