刚开始学习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. 浅谈一下关于使用css3来制作圆环进度条

    最近PC端项目要做一个这样的页面出来,其他的都很简单,关键在于百分比的圆环效果.我最初打算是直接使用canvas来实现的,因为canvas实现一个圆是很简便的. 下面贴出canvas实现圆环的代码,有 ...

  2. Hello 2017!

  3. mysql:SQL语句操作数据库中表和字段的COMMENT值

    转载:http://blog.163.com/inflexible_simple/blog/static/167694684201182601221758/ 参考文档不太给力啊,表注释和字段注释的资料 ...

  4. .net(C#)在vs2010版本下的MVC如何才能运行静态页面(html)

    正如,我上篇写的那样,那是在测试下,我所实现的方法,但是作为WEB项目,终究要发布的,故我把发布和切换在这说一下. 据我实测,我在按照我上篇改了Views下的Webconfig文件后,在解决方案下建了 ...

  5. TAP/TUN摘要

    TUN适用于IP帧.Tap适用于以太网帧.TAP摸拟一个以太网设备(以arp广播MAC识别),它操作第二层数据包如以太网数据帧.TUN模拟了网络层ip设备(以点对点的方式,使用ip标识),操作第三层数 ...

  6. 有关sublime text的插件安装

    .sumblime text 中的package control 插件包控件的安装步骤一:    Ctrl+` 调出console    粘贴代码: import urllib2,os; pf='Pa ...

  7. 初识ReactJs(一)

    React的开发背景 ReactJS官网地址:http://facebook.github.io/react/ Github地址:https://github.com/facebook/react J ...

  8. Linux mount的使用

    大家在使用Linux系统的时候,肯定用过一些共享文件的东西,比如FTP,Mount 等等,接下来我重点说一下Mount的用法: 现在有一台测试环境上面需要部署Mount服务器(10.10.10.27) ...

  9. wampServer安装注意

    http://www.glbwl.com/wampServer-403-forbidden.html http://jingyan.baidu.com/article/e75aca8578147d14 ...

  10. ADO总结测试数据库

    create database ADO测试 go use ADO测试 go create table Student ( Code ) not null primary key,--学生编号,主键 N ...