HDOJ.1800 Flying to the Mars(贪心+map)
Flying to the Mars
题意分析
有n个人,每个人都有一定的等级,高等级的人可以教低等级的人骑扫帚,并且他们可以共用一个扫帚,问至少需要几个扫帚。
这道题与最少拦截系统有异曲同工之妙。不同在于这道题可以排序,而最少拦截系统不能排序。我们想一下,把这些人排好序,并统计每个等级的人的个数。一次从最高等级到最低等级划掉一个人(可以理解为这些人互相教并且骑一个扫帚),一直划,直到最后一个人。这样可以看出来,扫帚的数量肯定是由某个等级的人数确定的。并且那个等级的人数最多。因此,只要统计出等数最多的等级就好,最后输出那个等级的人数。我采用了map映射,这样较为简单。
代码总览
/*
Title:HDOJ.1800
Author:pengwill
Date:2016-11-25
*/
#include <iostream>
#include <algorithm>
#include <map>
#include <stdio.h>
#define max 3005
using namespace std;
typedef map<int,int> mp;
mp p; mp::iterator iter;
int main()
{
int n;
while(scanf("%d",&n) != EOF){
int i,temp;
for(i = 0;i<n;i++){
scanf("%d",&temp);
p[temp]++;
}
int nmax = 0;
for(iter = p.begin();iter != p.end();iter++){
if(iter->second > nmax){
nmax = iter->second;
//titer = iter;
}
}
p.clear();
printf("%d\n",nmax);
}
return 0;
}
HDOJ.1800 Flying to the Mars(贪心+map)的更多相关文章
- HDOJ 1800 Flying to the Mars 盲目搜索......................so easy...........
check the original problem here:http://acm.hdu.edu.cn/showproblem.php?pid=1800 the AC code: #include ...
- --hdu 1800 Flying to the Mars(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Ac code: #include<stdio.h> #include<std ...
- 杭电 1800 Flying to the Mars(贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/Oth ...
- hdu 1800 Flying to the Mars
Flying to the Mars 题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位:序列长度不长于3000: input: 4 (n) 10 20 30 04 ou ...
- HDU 1800——Flying to the Mars——————【字符串哈希】
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 【HDOJ】1800 Flying to the Mars
1. 题目描述挺简单的一道题,给定$n$个大整数,求出现最多的次数. 2. 基本思路这题是可以使用哈希做,ELFHash等哈希都可以过. 3. 代码 /* 1800 */ #include <i ...
- HDU - 1800 Flying to the Mars 【贪心】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1800 题意 给出N个人的 level 然后 高的level 的 人 是可以携带 比他低level 的人 ...
- HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树
http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...
- HDU 1800 Flying to the Mars Trie或者hash
http://acm.hdu.edu.cn/showproblem.php?pid=1800 题目大意: 又是废话连篇 给你一些由数字组成的字符串,判断去掉前导0后那个字符串出现频率最高. 一开始敲h ...
随机推荐
- Windows运行机理——消息与消息队列
Windows运行机理这系列文章都是来至于<零基础学Qt4编程>——吴迪,个人觉得写得很好,所以进行了搬运和个人加工 Windows程序设计时一种基于消息的时机驱动方式的设计模式,完全不同 ...
- word record 2
word record 2 scavenger // si ga wen ger a person, animal or insect who takes what others have left ...
- Java应用基础微专业-入门篇
第1章--用程序来做计算 1.1 第一个Java程序 Mac version: Preference -> General -> Keys -> Search "Conte ...
- eclipse格式化
一.eclipse格式化的必要性 1.便于阅读 2.便于协作 二.eclipse格式化快捷键 ctrl shift + F
- 165. Merge Two Sorted Lists【LintCode by java】
Description Merge two sorted (ascending) linked lists and return it as a new sorted list. The new so ...
- 记一次Log4j2日志无法输出的 心酸史
问题描述:部分日志无法输出到日志文件中. 项目中的代码: @Resource private ConfigInfo configInfo; private static final Logger lo ...
- 【机器学习】多项式回归sklearn实现
[机器学习]多项式回归原理介绍 [机器学习]多项式回归python实现 [机器学习]多项式回归sklearn实现 使用sklearn框架实现多项式回归.使用框架更方便,可以少写很多代码. 使用一个简单 ...
- 线性代数之——对角化和 A 的幂
利用特征向量的属性,矩阵 \(A\) 可以变成一个对角化矩阵 \(\Lambda\). 1. 对角化 假设一个 \(n×n\) 的矩阵 \(A\) 有 \(n\) 个线性不相关的特征向量 \(x_1, ...
- nodejs笔记--模块篇(三)
文件模块访问方式通过require('/文件名.后缀') require('./文件名.后缀') requrie('../文件名.后缀') 去访问,文件后缀可以省略:以"/&qu ...
- ZOJ 1457 E-Prime Ring Problem
https://vjudge.net/contest/67836#problem/E A ring is compose of n circles as shown in diagram. Put n ...