HDU 5038 Grade北京赛区网赛1005
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5038
解题报告:就是输入n个数w,定义s = 10000 - (100 - w)^2,问s出现频率最高的是哪些,当所有的不同的s出现频率相同时,输出Bad Mushroom,当s只有一种时,直接输出。
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 const int maxn = 10000; 7 8 int num[maxn+5],ans[maxn+5]; 9 int main() 10 { 11 int T,n,kase = 1; 12 scanf("%d",&T); 13 while(T--) 14 { 15 scanf("%d",&n); 16 memset(num,0,sizeof(num)); 17 memset(ans,0,sizeof(ans)); 18 int w ,t,M = 0; 19 for(int i = 0;i < n;++i) 20 { 21 scanf("%d",&w); 22 t = 10000 - (100 - w) * (100 - w); 23 num[t]++; 24 M = max(M,num[t]); 25 } 26 int f = 0,tot = 0,tt = 0; 27 for(int i = 0;i <= 10000;++i) 28 if(num[i] == M) 29 { 30 ans[f++] = i; 31 tot++; 32 tt += num[i]; 33 } 34 sort(ans,ans+f); 35 printf("Case #%d:\n",kase++); 36 if(tot != 1 && tt == n) 37 { 38 puts("Bad Mushroom"); 39 continue; 40 } 41 for(int i = 0;i < f;++i) 42 printf(i == f - 1? "%d\n":"%d ",ans[i]); 43 } 44 return 0; 45 }