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
题目大意 给出了一列数,要求通过修改某些值,使得最终这列数变成有序的序列,非增或者非减的,求最小的修改量. 分析 首先我们会发现,最终修改后,或者和前一个数字一样,或者和后一个数字一样,这样才能修改量 ...
随机推荐
- 不小心rm删除文件怎么办
不小心rm删除文件怎么办 rm 命令的副作用越来越显现.而且rm掉之后的东西想找回来很困难.有2个原则: 1 永远不要在root下操作,尤其是rm命令 2 写一个别名,代替rm 我就是在~/.bash ...
- 视频处理控件TVideoGrabber视频捕捉设设备相关问题
选择一个视频捕捉设备 首先设置 VideoSource = vs_VideoCaptureDevice来选择一个视频捕捉设备作为一个视频源. 通过指定VideoDevice属性来选择当前的视频捕捉设备 ...
- GPS学习
1.每一个你不满意的现在,都有一个你没有努力的曾经. //ios根据gps坐标来计算两点间的距离 //x1,y1 点1的坐标 x2,y2点2的坐标 -(double) gps2m:(double)x1 ...
- java 调用grads 自动批量生成图片
将 -lbcx 命令 后面的4个参数(gs文件名.参数1.参数2.参数3) 放在单引号里面就可以执行了.
- freemarker为null处理
http://599073210-qq-com.iteye.com/blog/1401731
- PHP上传文件详解 错误提示
首先在php.ini里配置上载文件.有以下几个重要的配置单: 选项 默认值 说明 post_max_size 8M 控制以后的POST请求的最大规模.必须大于upload_max_filesize选项 ...
- vi编辑文件E437: terminal capability "cm" required 解决办法
E437: terminal capability "cm" required 这个错误一般是环境变量TERM没有配置或者配置错误所致. 解决办法: 执行export TERM=x ...
- 2016年6月25日 星期六 --出埃及记 Exodus 14:22
2016年6月25日 星期六 --出埃及记 Exodus 14:22 and the Israelites went through the sea on dry ground, with a wal ...
- codevs1137 计算系数
1137 计算系数 2011年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 给定一 ...
- iOS静态库和动态库的区别
一.什么是库? 库是共享程序代码的方式,一般分为静态库和动态库. 静态库:链接时完整地拷贝至可执行文件中,被多次使用就有多份冗余拷贝. 动态库:链接时不复制,程序运行时由系统动态加载到内存,供程序调用 ...