HDU5032--Grade

来源:互联网 发布:linux清空文件内容 编辑:程序博客网 时间:2024/06/01 10:10
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<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define maxn 1000010using namespace std;int a[maxn];int vis[maxn];int s[maxn];int main() {int T;scanf("%d", &T);for (int h= 1; h <= T; h++) {int t;int N;int m = 0;scanf("%d", &N);memset(vis, 0, sizeof(vis));for (int i = 0; i < N; i++) {scanf("%d", &t);a[i] = 10000 - pow((100 - t), 2);vis[a[i]]++;if (m < vis[a[i]]) m = vis[a[i]];}int flag=0;sort(a, a + N);int j = 0;for (int i = 0; i < N; i++) {if (vis[a[i]] == m) {if (j == 0) {s[j] = a[i];j++;}else {if (a[i] != s[j - 1]) {s[j] = a[i];j++;}}}}if (m*j<N) flag = 1;if (j == 1) flag = 1;printf("Case #%d:\n", h);if (!flag) printf("Bad Mushroom\n");else {printf("%d", s[0]);for (int i = 1; i < j; i++) {if (s[i] != s[i - 1]) {printf(" %d", s[i]);}}printf("\n");}}}

0 0