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. 「暑期训练」「基础DP」免费馅饼(HDU-1176)

    题意与分析 中文题就不讲题意了.我是真的菜,菜出声. 不妨思考一下,限制了我们决策的有哪些因素?一,所在的位置:二,所在的时间.还有吗?没有了,所以设dp[i][j]" role=" ...

  2. 刚安装的Linux Centos7使用yum安装firefox时提示:cannot find a valid baseurl for repo

    出现这个问题是因为yum在安装包的过程中,虽然已经联网,但是没法解析远程包管理库对应的域名,所以我们只需要在网络配置中添加上DNS对应的ip地址即可. 解决参考链接:https://blog.csdn ...

  3. .NET MVC和.NET WEB api混用时注意事项

    1.同时配置了mvc路由和api路由时,mvc路由无法访问(调用所有mvc路由全部404错误) 在Global.asax中,需注意路由注册的顺序,将api路由注册放在最后: 即将 void Appli ...

  4. error:no module named StringIO or cStringIO

    一般遇到没有某个模块问题的时候,通常的解决方法是pip相应的模块: 不过,鉴于Python2和python3的不同(让人头疼) 解决方法:在python3中,该模块被新的模块取代,即io. 重新imp ...

  5. vue.js学习之 跨域请求代理与axios传参

    vue.js学习之 跨域请求代理与axios传参 一:跨域请求代理 1:打开config/index.js module.exports{ dev: { } } 在这里面找到proxyTable{}, ...

  6. php分页类的实现与调用 (自我摘记)

    page.class.php <?php namespace Component; class Page { private $total; //数据表中总记录数 private $listRo ...

  7. Spring学习(二)—— java的动态代理机制

    在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而对于Spring的核心AOP来说,我们不但要知道怎么通过AOP来满足的 ...

  8. Android中Parcelabel对象的使用和理解

    1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...

  9. lintcode-179-更新二进制位

    179-更新二进制位 给出两个32位的整数N和M,以及两个二进制位的位置i和j.写一个方法来使得N中的第i到j位等于M(M会是N中从第i为开始到第j位的子串) 注意事项 In the function ...

  10. (十一)instanceof 和 getclass 的区别

    判断两个对象是否为同一类型,时常用到getclass 和 instanceof ,而这两个函数又是时常让人混淆.下面从一个例子说明两者的区别: public class Test_drive { pu ...