HDU 5038 Grade (水题,坑题)

题意:给 n 个数,输出众数,但是如果所有的频率都相同但数不同输出 Bad Mushroom。

析:直接记录个数直接暴力就,就是要注意只有一种频率的时候。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10000 + 10;
const int mod = 100000000;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
  return r >= 0 && r < n && c >= 0 && c < m;
}

int a[maxn];

int main(){
  int T;  cin >> T;
  for(int kase = 1; kase <= T; ++kase){
    scanf("%d", &n);
    memset(a, 0, sizeof a);
    for(int i = 0; i < n; ++i){
      int x;
      scanf("%d", &x);
      x = 10000 - (100-x) * (100-x);
      ++a[x];
    }
    int mmax = 0;
    vector<int> v;
    int cnt = 0;
    for(int i = 0; i <= 10000; ++i){
      if(a[i] == 0)  continue;
      ++cnt;
      if(mmax < a[i]){
        v.clear();
        mmax = a[i];
        v.push_back(i);
      }
      else if(mmax == a[i])  v.push_back(i);
    }
    printf("Case #%d:\n", kase);
    if(cnt == 1)  printf("%d", v[0]);
    else if(cnt == v.size())  printf("Bad Mushroom");
    else  for(int i = 0; i < v.size(); ++i){
      if(i)  putchar(‘ ‘);
      printf("%d", v[i]);
    }
    printf("\n");
  }
  return 0;
}

  

时间: 2024-10-10 17:52:28

HDU 5038 Grade (水题,坑题)的相关文章

HDU - 5038 Grade(水题/思维)

题面 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 \({s = 10000 - (100 - w)^2}\) What's

hdu 5038 Grade 水

用map,也可以用数组,少了个特判WA了一发. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <vector> #include <map> using namespace std; const int maxn=1000005; int n; int a[max

hdu 4920 Matrix multiplication(矩阵坑题)

http://acm.hdu.edu.cn/showproblem.php?pid=4920 被这道题虐了一下午,啥也不说了.继续矩阵吧. 超时就超在每步取余上,要放在最后取余,再者注意三个循环的次序. #include <stdio.h> #include <map> #include <set> #include <stack> #include <queue> #include <vector> #include <cma

hdu 5038 Grade(水)

题目链接: huangjing 思路: 这个题目应该随便怎么搞都可以,我说一下我的思路,可以根据题目的数据计算出价值的取值范围为0~10000,所以用一个1w的数组表示数组,下标代表价值,数组值代表数目, 然后这个题目要特判一下全是一样的值的情况. 题目: Grade Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 297    A

HDU 6034 Balala Power! (贪心+坑题)

题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后要注意的进位,然后排序,从大到小,给每个字符赋值,如果最后一个出现前导0,就得向前找一个最小的不在首字符的来交换,但不能动了相对的顺序. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <c

HDU 5038 Grade(数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5038 Problem Description 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 m

HDU 5038 Grade北京赛区网赛1005

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5038 解题报告:就是输入n个数w,定义s = 10000 - (100 - w)^2,问s出现频率最高的是哪些,当所有的不同的s出现频率相同时,输出Bad Mushroom,当s只有一种时,直接输出. 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm>

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

hdu 5038 Grade(简单模拟求解)2014 ACM/ICPC Asia Regional 北京 Online

Grade                                                                     Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives h