Ignatius and the Princess IV

点我跳转到题面

点我一起学习STL-MAP

题意分析

给出一个奇数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)的更多相关文章

  1. 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 ...

  2. HDU 1029 Ignatius and the Princess IV(数论)

    #include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...

  3. hdu 1029 Ignatius and the Princess IV(排序)

    题意:求出现次数>=(N+1)/2的数 思路:排序后,输出第(N+1)/2个数 #include<iostream> #include<stdio.h> #include ...

  4. HDU 1029 Ignatius and the Princess IV (动态规划、思维)

    Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K ( ...

  5. [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 ...

  6. HDOJ 1028 Ignatius and the Princess III (母函数)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  7. 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 ...

  8. HDU 1029 Ignatius and the Princess IV --- 水题

    HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...

  9. 【HDU - 1029】Ignatius and the Princess IV (水题)

    Ignatius and the Princess IV  先搬中文 Descriptions:   给你n个数字,你需要找出出现至少(n+1)/2次的数字 现在需要你找出这个数字是多少? Input ...

随机推荐

  1. 2019年猪年海报PSD模板-第七部分

    14套精美猪年海报,免费猪年海报,下载地址:百度网盘,https://pan.baidu.com/s/1pE3X9AYirog1W8FSxbMiAQ              

  2. java 素数问题

    1.素数 质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数. 2.java 实现 一般都要用不能被自己和其他数字整除判断,jdk中已经有更好的实现方法了. List<BigInte ...

  3. [CodeForce455A]Boredom

    题面描述 Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long ...

  4. 孤荷凌寒自学python第八十六天对selenium模块进行较详细的了解

    孤荷凌寒自学python第八十六天对selenium模块进行较详细的了解 (今天由于文中所阐述的原因没有进行屏幕录屏,见谅) 为了能够使用selenium模块进行真正的操作,今天主要大范围搜索资料进行 ...

  5. HDU 2492 Ping pong(数学+树状数组)(2008 Asia Regional Beijing)

    Description N(3<=N<=20000) ping pong players live along a west-east street(consider the street ...

  6. cookie,localstorge,sessionstorge三者总结

    相同点:都是客户端存储东西的: 不同: 1大小,cookie最小;locastorge最大 2 cookie设置好会在header头里面自动带的:但是ls和ss不会:ls同个浏览下不同网页(非跨域)都 ...

  7. JavaWeb基础 - 会话

    会话概述 什么是会话 简单的理解:用户打开浏览器,点击多个超链接,访问Web服务器上多个资源,然后关闭浏览器,整个过程称之为一次会话. 需要解决的问题 每个用户在使用浏览器与服务器会话的过程中,会产生 ...

  8. linux下安装多个jdk版本的切换问题

    下载地址: https://www.azul.com/downloads/zulu/ 解压: [root@localhost java]# tar -zxvf /usr/java/zulu8.38.0 ...

  9. 基于3D卷积神经网络的人体行为理解(论文笔记)(转)

    基于3D卷积神经网络的人体行为理解(论文笔记) zouxy09@qq.com http://blog.csdn.net/zouxy09 最近看Deep Learning的论文,看到这篇论文:3D Co ...

  10. 分享几个.Net计划任务组件

    Quartz http://www.quartz-scheduler.net/ Hangfire http://hangfire.io/ Install-Package Hangfire 使用OWIN ...