刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正。

时间限制: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
题目比较简单,直接给出代码
#include<stdio.h>
#include<stdlib.h> #define SWAP(a,b) tmp=a;a=b;b=tmp
#define SORT(a,b,c,tmp) if(a>b) \
{SWAP(a,b);} \
if(b>c) \
{SWAP(b,c);} \
if(a>b) \
{SWAP(a,b);}
#define ABS(a) (a)<0?(-a):(a)
#define MAX(a,b) a>b?a:b int main()
{
int x,y,z;
int Dc1,Dc2,Dc3;
int CrN=,CyN=,CbN=;
int MaxNum=,Num=;
int i,j,tmp;
char Color;
scanf("%d%d%d",&x,&y,&z);
SORT(x,y,z,tmp);
while((Color=getchar())!=EOF)
{
switch (Color)
{
case 'R':
CrN++;
Num++;
break;
case 'Y':
CyN++;
Num++;
break;
case 'B':
CbN++;
Num++;
break;
case '\n':
break;
default:
exit(EXIT_FAILURE);
break;
}
Dc1=CrN-CyN;
Dc1=ABS(Dc1);
Dc2=CrN-CbN;
Dc2=ABS(Dc2);
Dc3=CyN-CbN;
Dc3=ABS(Dc3);
SORT(Dc1,Dc2,Dc3,tmp);
if(x==Dc1&&y==Dc2&&z==Dc3)
{
CrN=;
CyN=;
CbN=;
MaxNum=MAX(Num,MaxNum);
Num=;
}
}
MaxNum=MAX(Num,MaxNum);
printf("%d\n",MaxNum);
return ;
}

hihoCoder#1135的更多相关文章

  1. hihocoder 1135 : Magic Box

    #1135 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. Whe ...

  2. hihocoder -1121-二分图的判定

    hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...

  3. Hihocoder 太阁最新面经算法竞赛18

    Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...

  4. hihoCoder太阁最新面经算法竞赛15

    hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...

  5. 【hihoCoder 1454】【hiho挑战赛25】【坑】Rikka with Tree II

    http://hihocoder.com/problemset/problem/1454 调了好长时间,谜之WA... 等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻ #include& ...

  6. 【hihocoder#1413】Rikka with String 后缀自动机 + 差分

    搞了一上午+接近一下午这个题,然后被屠了个稀烂,默默仰慕一晚上学会SAM的以及半天4道SAM的hxy大爷. 题目链接:http://hihocoder.com/problemset/problem/1 ...

  7. 【hihoCoder】1148:2月29日

    问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...

  8. 【hihoCoder】1288 : Font Size

    题目:http://hihocoder.com/problemset/problem/1288 手机屏幕大小为 W(宽) * H(长),一篇文章有N段,每段有ai个字,要求使得该文章占用的页数不超过P ...

  9. 【hihoCoder】1082: 然而沼跃鱼早就看穿了一切

      题目:http://hihocoder.com/problemset/problem/1082 输入一个字符串,将其中特定的单词替换成另一个单词   代码注意点: 1. getline(istre ...

随机推荐

  1. maven 使用tomcat插件 自动化部署war

    1.相关环境变量 idea tomcat8 maven3 2.增加tomcat user, 修改 $CATALINA_HOME/conf/tomcat-users.xml <tomcat-use ...

  2. Selenium IDE 基础教程

    Selenium IDE 基础教程 1.下载安装     a 在火狐浏览其中搜索附件组件,查找 Selenium IDE     b 下载安装,然后重启firefox 2.界面讲解      在菜单- ...

  3. adb shell使用

    adb shell可以用来操纵数据库 1.在cmd界面 输入adb shell 进入adb shell 2.使用cd 切换到工作目录:使用ls查看文件 3.使用sqlite3+数据库名字 打开某个数据 ...

  4. PUTTY用密钥登陆服务器

    1.puttygen生成private_key和public_key,保存private_key: 2.在 ~/.ssh/authorized_keys中添加public_key,(vi ~/.ssh ...

  5. SAP公司间采购订单关联交货单报表源代码(自己收藏)

    SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF } ...

  6. android Glide图片加载框架的初探

    一.Glide图片加载框架的简介 谷歌2014年开发者论坛会上介绍的图片加载框架,它让我们在处理不管是网路下载的图片还是本地的图片,减轻了很多工作量, 二.开发步骤: 1.添加链接库 compile ...

  7. Sudoku 数独游戏

    #include<iostream> using namespace std; bool heng(int **sudo, int a, int b, int value) { bool ...

  8. 习题 5: 更多的变量和打印 | 笨办法学 Python

    一. 简述 “格式化字符串(format string)” -  每一次你使用 ' ’ 或 " " 把一些文本引用起来,你就建立了一个字符串. 字符串是程序将信息展示给人的方式. ...

  9. 理解伪元素 :Before 和 :After

    层叠样式表(CSS)的主要目的是给HTML元素添加样式,然而,在一些案例中给文档添加额外的元素是多余的或是不可能的.事实上CSS中有一个特性允许我们添加额外元素而不扰乱文档本身,这就是“伪元素”. 你 ...

  10. ionic实现双击返回键退出功能

    实现这个功能需要四个步骤: 步骤一: 说明:因为需要和手机的硬件(返回按钮)打交道,而ionic本身是不具备该功能的,但是有一个东西可以:ng-cordova插件,这个插件是phoneGap为了能让i ...