HDU5038-Grade, grade

Source: Internet
Author: User

HDU5038-Grade, grade

Question Link


Question: use the formula given to obtain the value of each lattice mushroom and find the value with the most frequent occurrence. If the occurrence frequency is the same and there are other frequencies, the output frequency is the most frequent and the same value, this value is output in ascending order.

Idea: Simple simulation

Code:

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





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.