http://acm.hdu.edu.cn/showproblem.php?pid=5038

模拟水题

求出现次数最多的grade。如果有多个grade出现的次数一样多,且还有其他的grade,则把这些出现次数最多的grade按升序输出;否则,输出“Bad Mushroom”。

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
int n;
int s[1000005];
int cnt[10005];
int main(){
int _,w,cas = 1;
RD(_);
while(_--){
RD(n);
clr0(cnt);
for(int i = 0;i < n;++i){
scanf("%d",&w);
s[i] = 10000 - (100 - w)*(100 - w);
cnt[s[i]]++;
}
int mn = 20000000,mx = -1;
vector <int> ans;
for(int i = 0;i <= 10000;++i){
if(cnt[i]){
mn = min(cnt[i],mn);
mx = max(cnt[i],mx);
}
}
for(int i = 0;i <= 10000;++i){
if(cnt[i] == mx){
ans.push_back(i);
}
}
printf("Case #%d:\n",cas++);
if(mn == mx && ans.size() != 1){
puts("Bad Mushroom");
}else{
for(int i = 0;i < ans.size();++i){
printf("%d%c",ans[i]," \n"[i == ans.size() - 1]);
}
} }
return 0;
}

hdu 5038 求出现次数最多的grade的更多相关文章

  1. 一个字符串中可能包含a~z中的多个字符,如有重复,如String data="aavzcadfdsfsdhshgWasdfasdf",求出现次数最多的那个字母及次数,如有多个重复的则都求出。

    主要掌握String中的方法 char[] toCharArray()           将此字符串转换为一个新的字符数组. int indexOf(String str)           返回 ...

  2. hdu 1029 求出现次数过半的数

    题目传送门//res tp hdu 已知必定存在一个元素出现次数超过一半,考虑用栈 若当前元素等于栈顶元素,入栈,反之出栈,并将当前元素入栈 最终的栈顶元素即是所求 #include<iostr ...

  3. ✡ leetcode 169. Majority Element 求出现次数最多的数 --------- java

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  4. Maximum repetition substring (poj3693 后缀数组求重复次数最多的连续重复子串)

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6328   Acc ...

  5. UVALive-4670 AC自动机入门题 求出现次数最多的子串

    /** 链接:http://vjudge.net/problem/UVALive-4670 详见lrj训练指南P216 */ #include<bits/stdc++.h> using n ...

  6. 我的Java开发学习之旅------>求字符串中出现次数最多的字符串以及出现的次数

    金山公司面试题:一个字符串中可能包含a~z中的多个字符,如有重复,如String data="aavzcadfdsfsdhshgWasdfasdf",求出现次数最多的那个字母及次数 ...

  7. spoj687 后缀数组重复次数最多的连续重复子串

    REPEATS - Repeats no tags  A string s is called an (k,l)-repeat if s is obtained by concatenating k& ...

  8. POJ-3693-Maximum repetition substring(后缀数组-重复次数最多的连续重复子串)

    题意: 给出一个串,求重复次数最多的连续重复子串 分析: 比较容易理解的部分就是枚举长度为L,然后看长度为L的字符串最多连续出现几次. 既然长度为L的串重复出现,那么str[0],str[l],str ...

  9. POJ - 3693 Maximum repetition substring(重复次数最多的连续重复子串)

    传送门:POJ - 3693   题意:给你一个字符串,求重复次数最多的连续重复子串,如果有一样的,取字典序小的字符串. 题解: 比较容易理解的部分就是枚举长度为L,然后看长度为L的字符串最多连续出现 ...

随机推荐

  1. KEGG下载某物种最新的版本信息(斑马鱼为例)

    步骤一:打开链接并选择物种 http://www.genome.jp/kegg-bin/get_htext?hsa00001+3101 步骤二:对文件进行解析 步骤三:统计信息 一级结构(6大类): ...

  2. EasyUI多选的获取

    function deletePRE() { var rows = $('#dg').datagrid('getSelections'); var ids = []; var other_ids = ...

  3. tf.Session()、tf.InteractiveSession()

    tf.Session()和tf.InteractiveSession()的区别 官方tutorial是这么说的: The only difference with a regular Session ...

  4. inner join和outer join

    内连接           只连接匹配的行 左外连接        包含左边表的全部行(不管右边的表中是否存在与它们匹配的行),以及右边表中全部匹配的行 A left join B等价于A left ...

  5. 虚拟机安装Centos6.5服务器系统

    前言: 工作需要,研究Linux数日,写下此教程,意在给其他初学者参考学习,亦是给自己留作备用.好记性不如烂笔头,毕竟只是偶尔使用,留下教程,以备不时之需. 对于学习研究Linux的新手,个人推荐VM ...

  6. day11:vcp考试

    Q201. Which two options are available in the Virtual Machine Component Protection (VMCP) setting Res ...

  7. swift UICollectionView使用

    方法1:创建 的时候注册 layout /// 时间view private lazy var timeCollectionV: UICollectionView = { 1.直接注册 并设置好 UI ...

  8. ueditor使用注意

    问题1:后端配置项没有正常加载,上传插件不能正常使用! 我用的是开发版,1.4.3.3 .Net版 网上查了很多,后来发现只是配置的问题而已. 1.在根目录下:config.json 其中有Img上传 ...

  9. Java 检查异常(checked exception)和未检查异常(unchecked exception)区别理解

    所有异常类型都是 Throwable 类的子类,它包含Exception类和Error类,Exception又包括checked exception和unchecked exception. unch ...

  10. 在jmeter的beanshell中用java获取系统当前时间

    import java.util.*; int y,m,d,h,mi,s; Calendar cal=Calendar.getInstance(); y=cal.get(Calendar.YEAR); ...