HDU5038-Grade

题目链接


题意:用给出的公式求出每个格子蘑菇的数值,求出现频率最多的数值,如果存在出现频率一样的话并且还存在其他频率,输出频率最多且一样的数值,按升序,但要注意有且出现只有一种数值时,输出这种数值。

思路:简单模拟

代码:

#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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值