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. android 项目学习随笔六(网络缓存)

    1. 对SharePreference的封装 import android.content.Context; import android.content.SharedPreferences; /** ...

  2. python核心编程学习记录之数字

    仅用于整数的操作

  3. CDN流量放大攻击思路

    首先,为了对CDN进行攻击,我们必须清楚CDN的工作原理,这里我们再来简单介绍一下CDN的工作模型. CDN的全称是Content Delivery Network(内容分发网络),通过在网络各处的加 ...

  4. Hibernate,JPA注解@SecondaryTables

    使用类一级的 @SecondaryTable或@SecondaryTables注解可以实现单个实体到多个表的映射. 使用 @Column或者 @JoinColumn注解中的table参数可指定某个列所 ...

  5. php单例模式是怎么实现的呢

    <?php /** * 设计模式之单例模式 * $_instance必须声明为静态的私有变量 * 构造函数和析构函数必须声明为私有,防止外部程序new * 类从而失去单例模式的意义 * getI ...

  6. 如何在VS2013中新建WindowsService定时任务

    http://jingyan.baidu.com/article/cd4c2979e9330d756f6e6070.html 很多人都想做定时任务,但是没有不知道如何下手,现在就用WindowsSer ...

  7. Python 编码规范

    官网规范:https://www.python.org/dev/peps/pep-0008/ 1.不在同一句import中引用多个库 # 正确姿势: import os import sys # 错误 ...

  8. 删除 SQL Server 2005 Express 工具

    安装sql server 2008 management,提示错误:Sql2005SsmsExpressFacet 检查是否安装了 SQL Server 2005 Express 工具. 失败,已安装 ...

  9. 荒木毬菜 小情歌日文版 - 独身OL之歌

    咎(とが)めるつもりもないけどtogameru tumorimo naikedo并不想责备在身旁 暇(ひま)してる时间(じかん)をhimashiteru jikan wo无所事事的时间 パジャマの鸟( ...

  10. symfony在模板中生成url

    {{ path('homepage') }},这里的homepage是route配置文件的内容,或者叫别名.