HDOJ.1029 Ignatius and the Princess IV(map)
Ignatius and the Princess IV
题意分析
给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出。
用map做出映射,然后迭代器检查是否满足输出条件,是的话输出即可。
代码总览
/*
Title:HDOJ.1029
Author:pengwill
Date:2016-11-21
*/
#include <iostream>
#include <stdio.h>
#include <map>
using namespace std;
typedef map<int,int> mp;
mp p;
int main()
{
int n,temp,t;
while(scanf("%d",&n)!= EOF){
t = n;
while(n--){
scanf("%d",&temp);
p[temp]++;
}
mp::iterator iter;
temp = 1;
for(iter = p.begin();iter!=p.end();iter++){
//cout<<iter->first<<"\t"<<iter->second<<endl;
if(iter->second >= ((t+1)/2)){
printf("%d\n",iter->first);
break;
}
}
p.clear();
}
return 0;
}
HDOJ.1029 Ignatius and the Princess IV(map)的更多相关文章
- HDU 1029 Ignatius and the Princess IV (map的使用)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1029 Ignatius and the Princess IV Time Limit: 2000/10 ...
- HDU 1029 Ignatius and the Princess IV(数论)
#include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...
- hdu 1029 Ignatius and the Princess IV(排序)
题意:求出现次数>=(N+1)/2的数 思路:排序后,输出第(N+1)/2个数 #include<iostream> #include<stdio.h> #include ...
- HDU 1029 Ignatius and the Princess IV (动态规划、思维)
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- [ACM] hdu 1029 Ignatius and the Princess IV (动归或hash)
Ignatius and the Princess IV Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32767K (Ja ...
- HDOJ 1028 Ignatius and the Princess III (母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...
- HDU 1029 Ignatius and the Princess IV --- 水题
HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...
- 【HDU - 1029】Ignatius and the Princess IV (水题)
Ignatius and the Princess IV 先搬中文 Descriptions: 给你n个数字,你需要找出出现至少(n+1)/2次的数字 现在需要你找出这个数字是多少? Input ...
随机推荐
- MyEclipse相关用法介绍
MyEclipse相关用法介绍 ================================================================================ 编辑: ...
- Matlab2018年最新视频教程视频讲义(包含代码)
2018年Matlab最新视频教程视频讲义(包含代码),适合初学者入门进阶学习,下载地址:百度网盘, https://pan.baidu.com/s/1w4h297ua6ctzfturQ1791g 内 ...
- 「日常训练」Case of Matryoshkas(Codeforces Round #310 Div. 2 C)
题意与分析(CodeForces 556C) 为了将所有\(n\)个娃娃编号递增地串在一起(原先是若干个串,每个串是递增的), 我们有两种操作: 拆出当前串中最大编号的娃娃(且一定是最右边的娃娃). ...
- 使用python中读取配置文件
最近在接触利用python来写测试框架,本人也是个刚接触python,所以是个小菜鸟,今天开始,一点点的记录学习中的积累,方便以后的学习以及回顾,也希望能帮助跟我一样的小菜鸟们一步步的成长起来.那么, ...
- Siki_Unity_1-8_使用Unity开发2D游戏_PongGame
Unity 1-8 使用Unity开发2D游戏 PongGame 任务1:演示 http://pan.baidu.com/s/1pKUHsev; up2i 任务2:案例介绍 创建PongGame,注意 ...
- * 197. Permutation Index【LintCode by java】
Description Given a permutation which contains no repeated number, find its index in all the permuta ...
- Java学习 · 初识 异常机制
异常机制 1. 程序中的异常 a) b) 面对异常如何解决 i. 由开发者通过if-else来解决 代码臃肿 程序员需要花费很大精力 ii. ...
- 周期串 (Periodic Strings,UVa455)
#include<stdio.h> #include<string.h> int main(void) { int n,stlen,i,j; ]; while(scanf(&q ...
- Halcon介绍和下载安装视频教程
------------------------Halcon,Visionpro高清视频教程,点击下载视频--------------------------
- POJ 2540 Hotter Colder(半平面交)
Description The children's game Hotter Colder is played as follows. Player A leaves the room while p ...