标签:style http color io os ar for sp on
题意:用给出的公式求出每个格子蘑菇的数值,求出现频率最多的数值,如果存在出现频率一样的话并且还存在其他频率,输出频率最多且一样的数值,按升序,但要注意有且出现只有一种数值时,输出这种数值。
思路:简单模拟
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <algorithm> using namespace std; const int MAXN = 1e6; int vis[MAXN]; int n; int main() { int cas, t = 1; scanf("%d", &cas); while (cas--) { int n; scanf("%d", &n); memset(vis, 0, sizeof(vis)); int a, max = 0, cnt = 0, num = 0; for (int i = 0; i < n; i++) { scanf("%d", &a); a = 10000 - pow((100 - a), 2); if (!vis[a]) cnt++; if (max < a) max = a; vis[a]++; if (num < vis[a]) num = vis[a]; } printf("Case #%d:\n", t++); if (cnt * num == n && cnt > 1) { printf("Bad Mushroom\n"); continue; } int flag = 1; for (int i = 0; i <= max; i++) { if (vis[i] == num) { if (flag) { printf("%d", i); flag = 0; } else printf(" %d", i); } } printf("\n"); } return 0; }
标签:style http color io os ar for sp on
原文地址:http://blog.csdn.net/u011345461/article/details/39456059