hihoCoder#1135
刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正。
描述
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的更多相关文章
- hihocoder 1135 : Magic Box
#1135 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. Whe ...
- hihocoder -1121-二分图的判定
hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...
- Hihocoder 太阁最新面经算法竞赛18
Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...
- hihoCoder太阁最新面经算法竞赛15
hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...
- 【hihoCoder 1454】【hiho挑战赛25】【坑】Rikka with Tree II
http://hihocoder.com/problemset/problem/1454 调了好长时间,谜之WA... 等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻ #include& ...
- 【hihocoder#1413】Rikka with String 后缀自动机 + 差分
搞了一上午+接近一下午这个题,然后被屠了个稀烂,默默仰慕一晚上学会SAM的以及半天4道SAM的hxy大爷. 题目链接:http://hihocoder.com/problemset/problem/1 ...
- 【hihoCoder】1148:2月29日
问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...
- 【hihoCoder】1288 : Font Size
题目:http://hihocoder.com/problemset/problem/1288 手机屏幕大小为 W(宽) * H(长),一篇文章有N段,每段有ai个字,要求使得该文章占用的页数不超过P ...
- 【hihoCoder】1082: 然而沼跃鱼早就看穿了一切
题目:http://hihocoder.com/problemset/problem/1082 输入一个字符串,将其中特定的单词替换成另一个单词 代码注意点: 1. getline(istre ...
随机推荐
- javascript字符转直接量和转义字符
直接量: 你可以用单引号或者双引号来表示字符串的直接量.但是js的字符串必须是Unicode 字符序列. 转义字符: 主要用在字符串中,包涵控制字符,以及当前操作系统余元所不允许直接输入的字符. 转义 ...
- 一种更清晰的Android架构(转)
一种更清晰的Android架构 一种更清晰的Android架构 原文链接 : Architecting Android…The clean way? 译者 : Mr.Simple & So ...
- 回调函数及数组中sort()方法实现排序的原理
1.回调函数:把一个方法A当一个参数值传递到另外一个函数B中,在B执行的过程当中我们随时根据需求让A方法执行: 什么是回调 :它是异步编程基本的方法,需要异步处理的时候一般采用后续传递的方式,将后 ...
- iOS自动化编译方案
本文主要来源以下Bryce Zhang博主的文章,感谢博主的无私分享,转载请注明出处,尊重原创 然,根据Bryce Zhang文章进行实践过程中遇到一些问题,解决后在此做相应的总结.大神请绕道,觉得低 ...
- iOS - Card Identification 银行卡号识别
1.CardIO 识别 框架 GitHub 下载地址 配置 1.把框架整个拉进自己的工程,然后在 TARGETS => Build Phases => Link Binary With L ...
- spring+task配置
1.spring+task文件配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=& ...
- js实现对移动设备的检测
<script type="text/javascript"> if (browserRedirect()) { location.href = 'http:/phon ...
- asp.net 获取汉字字符串的拼音首字母,含多音字
需求:在很多时候数据查询的时候,我们希望输入某个人姓名的拼音首字母进行查询,例如“潘长江”,输入“pcj”,就能搜索潘长江相关信息. 实现: #region 获取汉字转换拼音 首字母 public s ...
- 使用JS实现轮播图的效果
其中的一些css样式代码就省略了,下面只把结构层html.行为层js的代码展示出来 ,看代码说事. 一.简单的轮播图 <div class="box" id="bo ...
- jquery on 绑定多个事件 多个元素
$('.wrap').on({ click:function(){ //事件1 ...... }, keyup:function() { //事件2 ....... }, keydown:functi ...