#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. JavaScript中创建自定义对象的方法

    本文内容参考JavaScript高级程序设计(第3版)第6章:面向对象的程序设计 ECMA-262中把对象定义为:“无序属性的集合,其属性可以包含基本值.对象或者函数.”我所理解的就是对象就是一个结构 ...

  2. 「CF932E」 Team Work

    题目链接 戳我 题意 有\(n\)个箱子,从中选出\(i\)个箱子,然后把\(k\)个不同的球装在这\(i\)个箱子中,求方案数. 实际上这题就是求: \[ \sum_{i=1}^nc_n^i*i^k ...

  3. git Problem with the SSL CA cert (path? access rights?)

    问题: [root@localhost opt]# git clone https://github.com/docker/docker.git 正克隆到 'docker'...fatal: unab ...

  4. django中ImageField模块使用

    https://blog.csdn.net/meylovezn/article/details/47124923

  5. 【bzoj3456】城市规划 dp+多项式求逆

    Description 刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了. 刚才说过, 阿狸的国家有n个城市, 现在国家需要在某些城市对之间建立一些贸易路线, 使得整个国家的任意两个城市都直接或 ...

  6. 【python跨目录调用】结合自己遇到的问题到解决问题,作个记录

    写PO的时候,想把page和case 文件分开存不同的文件夹,但是在调用模块的时候就出现了问题.后来终于解决了,记录下 ---------------------------------------- ...

  7. 23.3Sum(三数和为零)

    Level:   Medium 题目描述: Given an array nums of n integers, are there elements a, b, c in nums such tha ...

  8. LeetCode109. 有序链表转换二叉搜索树

    109. 有序链表转换二叉搜索树 问题描述 给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超 ...

  9. Fleury算法求欧拉路径

    分析: 小Ho:这种简单的谜题就交给我吧! 小Hi:真的没问题么? <10分钟过去> 小Ho:啊啊啊啊啊!搞不定啊!!!骨牌数量一多就乱了. 小Hi:哎,我就知道你会遇到问题. 小Ho:小 ...

  10. UESTC - 1137 数位DP

    #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...