#include <iostream>
#include <cmath>
#include <cstdio> using namespace std; void sort(int * a, int len)//冒泡升序排序
{
int i, j, t;
for(i = ;i < len-;i++)
for(j = ;j < len--i;j++)
if(a[j] > a[j+])
{
t = a[j];
a[j] = a[j+];
a[j+] = t;
}
} int main()
{
freopen("in1.txt", "r", stdin);
int x, y, z;
int Cr, Cy, Cb;
int max_num_ball = ;//球的最大个数
int cnt_ball = ;//当前球的个数
int a[];//按照升序存放x, y, z
int b[];//按照升序存放|Cr-Cy|, |Cy-Cb|, |Cb-Cr|
bool a_b_is_same;//判断a数组和b数组是否相同
Cr = Cy = Cb = ;
cin >> x >> y >> z;
a[] = x;
a[] = y;
a[] = z;//数组a初始化
sort(a, );
char color_ball;
cin >> color_ball;
while(!cin.eof())
{
switch(color_ball)
{
case 'R':
Cr++;
break;
case 'Y':
Cy++;
break;
case 'B':
Cb++;
break;
}
cnt_ball++;//当前球的个数统计
b[] = abs(Cr-Cy);
b[] = abs(Cy-Cb);
b[] = abs(Cb-Cr);//数组b初始化
sort(b, );
a_b_is_same = true;
for(int i = ;i < ;i++)
if(a[i] != b[i])
a_b_is_same = false;
if(cnt_ball > max_num_ball)
max_num_ball = cnt_ball;//对球数目的最大值进行刷新
if(a_b_is_same)
{
cnt_ball = ;
Cr = Cy = Cb = ;//所有的球消失
}
cin >> color_ball;
}
cout << max_num_ball << endl;
return ;
}

这一题总的来说还是挺简单的,我在比较前先排了序,这样比起来就会简单一点,我第一次提交时WA,后来发现是所有球消失时Cr、Cy、Cb没有赋值为0,改了之后就通过了。

hihoCoder题目之Magic Box的更多相关文章

  1. 【hihocoder】 Magic Box

    题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

  2. 微软2016校园招聘在线笔试之Magic Box

    题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

  3. hihocoder 1135 : Magic Box

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

  4. 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/ ...

  5. 【hihocoder 1499】A Box of Coins

    [题目链接]:http://hihocoder.com/problemset/problem/1499 [题意] [题解] 贪心,模拟; 从左往右对于每一列; 如果上下两个格子; ① 有一个格子超过了 ...

  6. [HDOJ 5155] Harry And Magic Box

    题目链接:HDOJ - 5155 题目大意 有一个 n * m 的棋盘,已知每行每列都至少有一个棋子,求可能有多少种不同的棋子分布情况.答案对一个大素数取模. 题目分析 算法1: 使用容斥原理与递推. ...

  7. 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 ...

  8. HDU-5155 Harry And Magic Box

    题目描述 在\(n*m\)的矩阵内每一行每一列都有钻石,问钻石分布的种类? 答案有可能很大,所以输出答案对\(1000000007\)取模. Input 对于每个测试用例,有两个整数\(n\)和\(m ...

  9. [Hdu-5155] Harry And Magic Box[思维题+容斥,计数Dp]

    Online Judge:Hdu5155 Label:思维题+容斥,计数Dp 题面: 题目描述 给定一个大小为\(N*M\)的神奇盒子,里面每行每列都至少有一个钻石,问可行的排列方案数.由于答案较大, ...

随机推荐

  1. Servlet的概念与用法

    Servlet: Servlet(Servlet+Applet) Servlet是一种独立于平台和协议的服务器端Java应用程序,通用Servlet      可以生成动态Web页面.Servlet还 ...

  2. [转]Why you shouldn't use set (and what you should use instead)

    Why you shouldn't use set (and what you should use instead) --- stl::set和sorted ector对比Matt Austern ...

  3. SDUT OJ 数据结构实验之串三:KMP应用

    数据结构实验之串三:KMP应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  4. 【离散数学】 SDUT OJ 集合的包含

    集合的包含 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 已知含n个元素的集合的子集 ...

  5. 5. pytest的断言

    一.pytest 支持Python自带的标准断言 def f(): return 3 def test_function(): assert f() == 4 pytest 的断言报告,也很丰富,和详 ...

  6. WebStorm ES6 语法支持设置和ES6语法的JS文件编译为ES5语法文件

    ECMAScript 6是JavaScript语言的下一代标准,已经在2015年6月正式发布了.Mozilla公司将在这个标准的基础上,推出JavaScript 2.0.ES6的目标,是使得JavaS ...

  7. C++_类入门3-嵌套类

    可以将类B声明在另一个类中.在另一个类A中声明的类B被称为嵌套类(nested class). 类A的成员函数可以创建和使用嵌套类B的对象. 当且仅当声明为公有部分时,才能在类A的外面使用嵌套类.而且 ...

  8. JAVA数据结构--希尔排序

    希尔排序通过将比较的全部元素分为几个区域来提升插入排序的性能.这样可以让一个元素可以一次性地朝最终位置前进一大步.然后算法再取越来越小的步长进行排序,算法的最后一步就是普通的插入排序,但是到了这步,需 ...

  9. ssm框架搭建出现的异常:The import org.springframework cannot be resolved

    1.检查是否有这个包;是否在maven依赖中添加了spring-context.,检查后我有这个包,而且在仓库中找到了 2.怀疑没有下完整,将其删除又导了一遍,还是报错. 3.后来重启了一遍eclip ...

  10. Fliptile (dfs+二进制压缩)

    Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He ha ...