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

时间: 2024-08-05 19:11:02

HDU5038-Grade的相关文章

BZOJ 1592: [Usaco2008 Feb]Making the Grade 路面修整( dp )

最优的做法最后路面的高度一定是原来某一路面的高度. dp(x, t) = min{ dp(x - 1, k) } + | H[x] - h(t) | ( 1 <= k <= t ) 表示前 i 个路面单调不递减, 第 x 个路面修整为原来的第 t 高的高度. 时间复杂度O( n³ ). 令g(x, t) = min{ dp(x, k) } (1 <= k <= t), 则转移O(1), g() 只需在dp过程中O(1)递推即可, 总时间复杂度为O( n² ) 然后单调不递增也跑一遍

POJ 3666 Making the Grade [DP]

题意: 给定一个序列,以最小代价将其变成单调不增或单调不减序列,这里的代价看题目公式. 思路: 很容易想到是DP. 1. 对前i个序列,构成的最优解其实就是与两个参数有关.一个是这个序列处理后的最大值mx,和这个序列处理的代价值cost. 显然最大值mx最小最好(这样第i+1个值可以不花代价直接接在其后面的可能性更大),cost最小也最好(题意要求),但是两者往往是鱼和熊掌. 用dp[i][j]表示:前i个数构成的序列,这个序列最大值为j,dp[i][j]的值代表相应的cost. 所以状态转移方

Furniture grade plywood from Long Da Wood xzml

Glad to hear that you're on the market for plywood products. We specialize in this field for 16 years, with good quality and competitive price two hour reach Qingdao port, this is how we keep good quality and competitive prices for global valued cust

Making the Grade POJ - 3666

A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up or down a single slope, but they are not fond of an alternating succession of hills and valleys. FJ would like t

POJ3666Making the Grade[DP 离散化 LIS相关]

Making the Grade Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6445   Accepted: 2994 Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up

[2016-03-28][POJ][3666][]Making the Grade]

时间:2016-03-28 17:23:08 星期一 题目编号:[2016-03-28][POJ][3666][]Making the Grade] 分析:dp[i][j]表示把改到第i个数,且把a[i]改成b[i]需要的最少代价,已知b[j]递增,dp[i][j]由dp[i - 1][k]递推过来,如果改成非增,那么就要求 a[j] <= a[k],所以dp[i][j] = min(dp[i - 1][k] + d) k < j; #include <algorithm> #in

【POJ 3666】Making the Grade

Making the Grade Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4962   Accepted: 2348 Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up

poj3666(Making the Grade)

Description A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up or down a single slope, but they are not fond of an alternating succession of hills and valleys. FJ

Different grade different reused times for film faced plywood

In the market of formwork panels there are many kinds of wooden board for different usage. The main boards are the H20 timber beam, Pine LVL scaffolding board and film faced plywood. There are many different scales' factories that produce these plywo

hdu 5038 Grade

Grade Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 360    Accepted Submission(s): 203 Problem Description Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of