HDU 5038 Grade

来源:互联网 发布:网络课程运营 编辑:程序博客网 时间:2024/05/02 01:05

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.

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.

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”.

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

其实我觉得这题的关键在于读懂他到底想说什么。。。他的意思应该是如果数目最大的有多个,但没有其他数目上小于其的数的话,那就不成立,也就是说,只有当有多个数数目都是最大的,且所有的数都在数目最大的那种情况中时才算不成立(注意如果只有一个数那他还是成立的)

#include <stdio.h>#include<vector>#include <cstring>#include<algorithm>using namespace std;  int a[1000000+10];int re[30000];int l,num[30000];int ans[30000];vector<int> v;int main(){int t;int n;int i,j,k;int icase;int maxnum;scanf("%d",&t);for(icase=1;icase<=t;icase++){memset(num,0,sizeof(num));l=0,maxnum=0;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d",&a[i]);int s=10000-(100-a[i])*(100-a[i]);if(l==0){re[++l]=s;num[l]=1;v.clear();v.push_back(1);maxnum=1;}else{int key=1;for(j=1;j<=l;j++){if(re[j]==s){num[j]++;if(num[j]>maxnum){maxnum=num[j];v.clear();v.push_back(j);}else if(num[j]==maxnum){v.push_back(j);}key=0;break;}}if(key){re[++l]=s;num[l]=1;if(maxnum==1){v.push_back(l);}}}}printf("Case #%d:\n",icase);if(l==v.size()&&l>1)printf("Bad Mushroom\n");else{for(i=0;i<v.size();i++)ans[i]=re[v[i]];sort(ans,ans+i);for(i=0;i<v.size()-1;i++)printf("%d ",ans[i]);printf("%d\n",ans[i]);}}return 0;}


1 0
原创粉丝点击