HDU 5038 Grade北京赛区网赛1005

时间:2022-05-26 02:49:27

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5038

解题报告:就是输入n个数w,定义s = 10000 - (100 - w)^2,问s出现频率最高的是哪些,当所有的不同的s出现频率相同时,输出Bad Mushroom,当s只有一种时,直接输出。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = ; int num[maxn+],ans[maxn+];
int main()
{
int T,n,kase = ;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(num,,sizeof(num));
memset(ans,,sizeof(ans));
int w ,t,M = ;
for(int i = ;i < n;++i)
{
scanf("%d",&w);
t = - ( - w) * ( - w);
num[t]++;
M = max(M,num[t]);
}
int f = ,tot = ,tt = ;
for(int i = ;i <= ;++i)
if(num[i] == M)
{
ans[f++] = i;
tot++;
tt += num[i];
}
sort(ans,ans+f);
printf("Case #%d:\n",kase++);
if(tot != && tt == n)
{
puts("Bad Mushroom");
continue;
}
for(int i = ;i < f;++i)
printf(i == f - ? "%d\n":"%d ",ans[i]);
}
return ;
}