刚开始学习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. replace和replaceAll

    replace():不可以正则 replaceAll()参数十一正则 replaceFirst()参数是一个正则,匹配第一次出现的 package entity; public class Test2 ...

  2. 【转】Python3.x和Python2.x的区别

    这个星期开始学习Python了,因为看的书都是基于Python2.x,而且我安装的是Python3.1,所以书上写的地方好多都不适用于Python3.1,特意在Google上search了一下3.x和 ...

  3. 【java基础】 合并两个类型相同的list

    将两个类型相同的list合并,可以用 addAll(Collection<? extends E> c) import java.util.ArrayList; import java.u ...

  4. mybatis原理

    http://blog.csdn.net/column/details/mybatis-principle.html?page=1

  5. [sqoop1.99.7] sqoop入门-下载、安装、运行和常用命令

    一.简介 Apache Sqoop is a tool designed for efficiently transferring data betweeen structured, semi-str ...

  6. 推荐两个谷歌的json-view插件(附带下载分享地址)

    1.JSONView 网盘下载地址:http://pan.baidu.com/s/1hrGlaVa 效果图: 2.JSON-handle 网盘下载地址:http://pan.baidu.com/s/1 ...

  7. JS添加父节点的方法。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. ARM+LINUX 项目学习总结

    一.确定功能 二.系统移植 1. 根据具体板子修改u-boot (三星的开发板资料) 2. 根据具体板子和功能修改内核 (基本的驱动) 3. 移植busybox 三.驱动修改编写 四.应用编程 附1 ...

  9. <python 深入理解>变量交换x,y=y,x实现机制--元组

    python中有一种赋值机制即多元赋值,采用这种方式赋值时,等号两边的对象都是元组并且元组的小括号是可选的.通常形式为 x, y, z = 1, 2, 'a string' 等同于 (x, y, z) ...

  10. Windows 10系统更换Windows 7系统磁盘分区注意事项一

    新买的电脑预装系统是WIN10,考虑到兼容性问题,打算更换为WIN7,但在新机上不能直接装WIN7系统,需要在BIOS启动中做一点小改动. 原因分析:由于Windows 8采用的是UEFI引导和GPT ...