HDU 5038 Grade(分级)
|
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(分级)的更多相关文章
- HDU 5038 Grade北京赛区网赛1005
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5038 解题报告:就是输入n个数w,定义s = 10000 - (100 - w)^2,问s出现频率最高 ...
- HDU 5038 Grade
解题思路:这题最关键的是要读懂题意,If not all the value are the same but the frequencies of them are the same, there ...
- HDU 5038 Grade (水题,坑题)
题意:给 n 个数,输出众数,但是如果所有的频率都相同但数不同输出 Bad Mushroom. 析:直接记录个数直接暴力就,就是要注意只有一种频率的时候. 代码如下: #pragma comment( ...
- hdu 5038 求出现次数最多的grade
http://acm.hdu.edu.cn/showproblem.php?pid=5038 模拟水题 求出现次数最多的grade.如果有多个grade出现的次数一样多,且还有其他的grade,则把这 ...
- hdu 5038 水题 可是题意坑
http://acm.hdu.edu.cn/showproblem.php?pid=5038 就是求个众数 这个范围小 所以一个数组存是否存在的状态即可了 可是这句话真恶心 If not all ...
- hdu 5038 (2014北京网络赛G 排序水题)
题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题 ...
- HDU5003:Osu!(签到题)HDU5038:(签到题,题意很坑)
HDU 5003 水题,直接上代码(因为题意读错了,WA了一遍). #include <iostream> #include <string.h> #include <s ...
- 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 ...
- hdu 3666 Making the Grade
题目大意 给出了一列数,要求通过修改某些值,使得最终这列数变成有序的序列,非增或者非减的,求最小的修改量. 分析 首先我们会发现,最终修改后,或者和前一个数字一样,或者和后一个数字一样,这样才能修改量 ...
随机推荐
- c# 操作xml题目
download! 1.新建一个文本文件,命名为:projects.txt. 2.将后缀名改为projects.xml. 3.用记事本编辑该文件.使用utf-8编码.内容如下: <?xml v ...
- 强制类型转换(const_cast)
[1] const_cast的作用 一.常量指针被转化成非常量指针,并且仍然指向原来的对象: 二.常量引用被转换成非常量引用,并且仍然指向原来的对象: 三.常量对象被转换成非常量对象. [2] 实例代 ...
- 【python cookbook】【字符串与文本】2.在字符串的开头或结尾处做文本匹配
问题:在字符串的开头或结尾处按照指定的文本模式做检查,例如检查文件的扩展名.URL协议类型等: 解决方法:使用str.startswith()和str.endswith()方法 >>> ...
- linux系统修改CST时区
================================================= [root@tzyyserveryg ~]# date -R Fri, 28 Nov 2014 08 ...
- Gift Hunting(分组背包)
Gift Hunting Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- In Action(SPFA+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- hust 1010 最短循环节点
题目链接:http://acm.hust.edu.cn/problem/show/1010 KMP失配指针的利用: next数组前缀和后缀最长公共长度,这样len - next[len];就是最短的循 ...
- pip命令使用国内pypi镜像源加速在线安装
参考:http://www.cnblogs.com/yudar/p/4444097.html 用easy_install和pip来安装第三方库很方便 它们的原理其实就是从Python的官方源pypi. ...
- 一个html5开发工具
今天推荐一个Html5开发工具 sublimetext3 找了一个注册码 可用 —– BEGIN LICENSE —– Michael Barnes Single User License EA7E- ...
- Java Swing的进化
摘 要:Swing已是一个比较老的工具集了,在美观的用户界面出来之前需要开发很长时间.它缺少一些你在开发富UI时所需的组件.幸运地是,像 Substance,SwingX及Java Look-and_ ...