Description

题目描述

Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushrooms and ask him to grade each mushroom according to its weight. Suppose the weight of a mushroom is w, then it’s grade s is

s = 10000 - (100 - w)^2

What’s more, Ted also has to report the mode of the grade of these mushrooms. The mode is the value that appears most often. Mode may not be unique. If not all the value are the same but the frequencies of them are the same, there is no mode.

Teb是Always Cook Mushroom (ACM)的员工。老板Matt给了他一包蘑菇叫他按质量分级。假设蘑菇的质量为w,那么它的等级为:

s = 10000 - (100 - w)^2

并且,Teb还得报告这些蘑菇等级的众数。众数就是最常出现的值。众数可不唯一。如果所有值各不相同但出现的频率一样,则没有众数。

Input

输入

The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.

The first line of each test cases contains one integers N (1<=N<=10^6),denoting the number of the mushroom.

The second line contains N integers, denoting the weight of each mushroom. The weight is greater than 0, and less than 200.

输入的首行是一个整数T表示测试样例的数量。接下来T个测试样例。

每个测试样例的第一行有一个整数N(1<=N<=10^6),表示蘑菇的数量。

第二行有N个整数,表示每个蘑菇的质量。质量大于0,小于200。

Output

输出

For each test case, output 2 lines.

The first line contains "Case #x:", where x is the case number (starting from 1)

The second line contains the mode of the grade of the given mushrooms. If there exists multiple modes, output them in ascending order. If there exists no mode, output “Bad Mushroom”.

对于每个测试样例,输出2行。

第一行为"Case #x:",这里的x表示样例的序号(从1开始)。

第二行为给定蘑菇其等级的众数。如果存在多个众数,升序输出。如果不存在,则输出“Bad Mushroom”。

Sample Input - 输入样例

Sample Output - 输出样例

3

6

100 100 100 99 98 101

6

100 100 100 99 99 101

6

100 100 98 99 99 97

Case #1:

10000

Case #2:

Bad Mushroom

Case #3:

9999 10000

【题解】

  注意Bad Mushroom的条件,然后是如果只有一个数,那么那个数即是那组数据的众数。

  用sort排个序就出来了。

【代码 C++】

 #include<cstdio>
#include<algorithm>
struct point{
int v, c;
}data[];
bool cmp(point A, point B){
if (A.c ^ B.c) return A.c > B.c;
return A.v > B.v;
}
int main(){
int T, i, j, N, nb, opt[];
for (j = ; j < ; ++j) opt[j] = - j*j;
while (~scanf("%d", &T)){
for (i = ; i <= T; ++i){
printf("Case #%d:\n", i);
scanf("%d", &N);
for (j = ; j <= ; ++j) data[j].c = , data[j].v = j;
for (j = ; j < N; ++j){
scanf("%d", &nb);
if (nb>) nb -= ;
else nb = - nb;
++data[nb].c;
}
std::sort(data, data + , cmp);
nb = data[].c;
for (j = ; data[j].c == nb; ++j) N -= data[j].c;
if (N || j == ){
printf("%d", opt[data[].v]);
for (j = ; data[j].c == nb; ++j) printf(" %d", opt[data[j].v]);
puts("");
}
else puts("Bad Mushroom");
}
}
return ;
}

HDU 5038

HDU 5038 Grade(分级)的更多相关文章

  1. HDU 5038 Grade北京赛区网赛1005

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5038 解题报告:就是输入n个数w,定义s = 10000 - (100 - w)^2,问s出现频率最高 ...

  2. HDU 5038 Grade

    解题思路:这题最关键的是要读懂题意,If not all the value are the same but the frequencies of them are the same, there ...

  3. HDU 5038 Grade (水题,坑题)

    题意:给 n 个数,输出众数,但是如果所有的频率都相同但数不同输出 Bad Mushroom. 析:直接记录个数直接暴力就,就是要注意只有一种频率的时候. 代码如下: #pragma comment( ...

  4. hdu 5038 求出现次数最多的grade

    http://acm.hdu.edu.cn/showproblem.php?pid=5038 模拟水题 求出现次数最多的grade.如果有多个grade出现的次数一样多,且还有其他的grade,则把这 ...

  5. hdu 5038 水题 可是题意坑

    http://acm.hdu.edu.cn/showproblem.php?pid=5038 就是求个众数  这个范围小 所以一个数组存是否存在的状态即可了 可是这句话真恶心  If not all ...

  6. hdu 5038 (2014北京网络赛G 排序水题)

    题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题 ...

  7. HDU5003:Osu!(签到题)HDU5038:(签到题,题意很坑)

    HDU 5003 水题,直接上代码(因为题意读错了,WA了一遍). #include <iostream> #include <string.h> #include <s ...

  8. hdu 1084 What Is Your Grade?

    http://acm.hdu.edu.cn/showproblem.php?pid=1084 What Is Your Grade? Time Limit: 2000/1000 MS (Java/Ot ...

  9. hdu 3666 Making the Grade

    题目大意 给出了一列数,要求通过修改某些值,使得最终这列数变成有序的序列,非增或者非减的,求最小的修改量. 分析 首先我们会发现,最终修改后,或者和前一个数字一样,或者和后一个数字一样,这样才能修改量 ...

随机推荐

  1. button改变背景与文字颜色

    1.定义/zhsh/res/color/txt_guide_selector.xml <?xml version="1.0" encoding="utf-8&quo ...

  2. android 学习随笔二十一(内容提供者 )

    一.内容提供者* 应用的数据库是不允许其他应用访问的* 内容提供者的作用就是让别的应用访问到你的私有数据* 自定义内容提供者,继承ContentProvider类,重写增删改查方法,在方法中写增删改查 ...

  3. Linux内存管理原理【转】

    转自:http://www.cnblogs.com/zhaoyl/p/3695517.html 本文以32位机器为准,串讲一些内存管理的知识点. 1. 虚拟地址.物理地址.逻辑地址.线性地址 虚拟地址 ...

  4. drupal 自定义表单调用autocomplete主标签实现方法

    代码如下: <php function module_name_form() { $form = array(); $form['city'] = array( '#title' => t ...

  5. 在JS函数中执行C#中的函数、字段

    1.调用字段 cs文件的代码: ; protected void Page_Load(object sender, EventArgs e) { id = ; } js页面的代码: function ...

  6. Oracle存储过程返回游标实例详解

    复制代码 代码如下:CREATE OR REPLACE PROCEDURE PROCSENDEMAIL(P_TXT VARCHAR2, P_SUB VARCHAR2, P_SENDOR VARCHAR ...

  7. bootstrap 列表 表格 表单 复选 单选 多选 输入框组

    一.列表 ul li 二.表格 table  (http://www.runoob.com/bootstrap/bootstrap-tables.html) 1. 基本表格 <table cla ...

  8. android应用的数据应该保存到哪儿

    王永超王永超嫖娼 做android app开发会涉及到不同数据的保存,比如数据缓存,客户登陆信息保存,客户状态的保存等等. 那针对这不同的数据我们应该保存在什么地方呢? 1.应用卸载也不会删除的数据 ...

  9. http协议了解

    在web应用中,服务器把网页的HTML代码发送给浏览器,让浏览器显示出来,浏览器和服务器之间的传输协议就是HTTP协议.HTTP是在网络上传输HTML的协议,用于浏览器和服务器之间的通信. 一个网页打 ...

  10. 7.进度条(ProgressBar)

    默认为圆形,类似加载的样子,如果想要设置为下载的样式,可以选择它的样式为横向. style="?android:attr/progressBarStyleHorizontal" 顺 ...