HDOJ 5038 Grade (模拟)
来源:互联网 发布:php授权系统源码下载 编辑:程序博客网 时间:2024/06/05 16:50
Grade
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1450 Accepted Submission(s): 615
Problem 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.
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.
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.
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.
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”.
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”.
Sample Input
36100 100 100 99 98 1016100 100 100 99 99 1016100 100 98 99 99 97
Sample Output
Case #1:10000Case #2:Bad MushroomCase #3:9999 10000
题意:用给出的公式求出每个蘑菇的grade,求出现次数最多的grade。如果有多个grade出现的次数一样多,且还有其他的grade,则把这些出现次数最多的grade按升序输出;否则,输出“Bad Mushroom”。
思路:模拟就行了
总结:刚开始看错了题,写了好几次都没写对,最后看了discuss才发现理解错了题意
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 100100#define LL long long#define ll __int64#define INF 0xfffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)using namespace std;int num[MAXN];int ans[MAXN];int main(){int t,a,i,n;int cas=0;scanf("%d",&t);while(t--){scanf("%d",&n);mem(num);int M=-1,mi=INF;for(i=0;i<n;i++){scanf("%d",&a);int b=10000-(100-a)*(100-a);mi=min(mi,b);M=max(M,b);num[b]++;}int mm=-1;for(i=mi;i<=M;i++)mm=max(mm,num[i]);int cnt=0;int k=0;for(i=mi;i<=M;i++){if(num[i])k++;if(mm==num[i]){ans[cnt++]=i;}}printf("Case #%d:\n",++cas);if(k*mm==n&&k>1)printf("Bad Mushroom\n");else{sort(ans,ans+cnt);for(i=0;i<cnt-1;i++)printf("%d ",ans[i]);printf("%d\n",ans[i]);}}return 0;}
0 0
- HDOJ 5038 Grade (模拟)
- hdu - 5038 - Grade(模拟)
- HDOJ 5038 Grade
- HDOJ 5038 Grade
- hdoj 5038 Grade【众数】
- HDU-#5038 Grade(模拟+Hash)
- hdu 5038 Grade(简单模拟求解)2014 ACM/ICPC Asia Regional 北京 Online
- hdu 5038 Grade(简单模拟求解)2014 ACM/ICPC Asia Regional 北京 Online
- hdu 5038 Grade(水)
- HDU 5038 Grade(数学)
- HDU 5038 Grade(哈希水题)
- HDU 5038 Grade(水~)
- hdu 5038 Grade(分级)
- HDU 1048 What Is Your Grade? (简单模拟)
- codeforces 719C Efim and Strange Grade (复杂模拟)
- codeforces 719 C. Efim and Strange Grade(模拟)
- codeforces 719 C Efim and Strange Grade (模拟)
- hdu 5038 Grade(北京网络赛)
- dom4j与xpath
- iOS中ARC项目使用MRC文件或MRC项目使用ARC
- c#获取今天开始时间的时间戳,以及时间戳和时间格式转换
- Android 6.0 使用 Apache HttpClient
- jQuery源码分析16--jQuery的each迭代器
- HDOJ 5038 Grade (模拟)
- MySQL 字符编码
- 获取相对于窗口(window)的坐标
- com.baoyz.swipemenulistview.SwipeMenuListView$1 cannot be cast to android.widget.BaseAdapter
- CentOS6.5下安装Samba服务器
- 利用NSURLSession请求/下载文件
- iOS---上传图片时修改图片大小
- 使用gulp构建前端工程浅谈
- JMeter学习(八)JDBC测试计划-连接Oracle