标签:
题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad。。。。
题解:统计数字个数和频率,排序后输出。
Sample Input
3
6
100 100 100 99 98 101
6
100 100 100 99 99 101
6
100 100 98 99 99 97
Sample Output
Case #1:
10000
Case #2:
Bad Mushroom
Case #3:
9999 10000
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <cmath> 6 # define LL long long 7 using namespace std ; 8 9 struct Num 10 { 11 int cnt ; 12 int num ; 13 14 }save[10010]; 15 16 int v[10010] ; 17 18 bool cmp(Num x , Num y) 19 { 20 return (x.cnt == y.cnt && x.num < y.num ||x.cnt > y.cnt) ; 21 } 22 23 int main () 24 { 25 //freopen("in.txt","r",stdin) ; 26 int T ; 27 scanf("%d" , &T) ; 28 int Case = 1 ; 29 while(T--) 30 { 31 memset(v, 0, sizeof(v)); 32 int n ; 33 scanf("%d" , &n) ; 34 int a ; 35 int i , j ; 36 int k = 0 ; 37 for (i = 0 ; i < n ; i++) 38 { 39 scanf("%d" , &a) ; 40 int t = 10000 - (100 - a) * (100 - a); 41 if (v[t] == 0) 42 { 43 v[t]++; 44 save[k].cnt = 0 ; 45 save[k].num = t ; 46 k++ ; 47 } 48 else 49 v[t]++; 50 } 51 for (i = 0 ; i < k ; i++) 52 save[i].cnt = v[save[i].num] ; 53 sort(save , save+k , cmp) ; 54 int m = 1 ; 55 for (i = 0; i < k - 1; i++) 56 { 57 if (save[i].cnt == save[i + 1].cnt) 58 m++; 59 else 60 break; 61 } 62 printf("Case #%d:\n" , Case++) ; 63 if (m == k && k!=1) 64 { 65 printf("Bad Mushroom\n") ; 66 continue ; 67 } 68 for (i = 0; i < m-1; i++) 69 printf("%d " , save[i].num) ; 70 printf("%d\n" , save[m-1].num) ; 71 } 72 73 return 0 ; 74 }
标签:
原文地址:http://www.cnblogs.com/-Buff-/p/4660208.html