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. meta-data获取小结

    android 开发中:   在AndroidManifest.xml中,<meta-data>元素可以作为子元素,   被包含在<activity>.<applicat ...

  2. uvaoj1339 - Ancient Cipher(思维题,排序,字符串加密)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. mysql数据库基本操作命令

    1.登录命令 mysql -u root -p "password" 2.列出所有数据库 show databases; 3.使用数据库 use db_name 4.列出数据库中所 ...

  4. <cerrno>

    文件头名称: <cerrno>(errno.h) 文件头描述: 文件内定义了如下的宏  errno 最后一个错误代码 加上其他至少的三个宏常量:EDOM,ERANGE 和EILSEQ 宏定 ...

  5. Angular6项目搭建

    参照 草根专栏- ASP.NET Core + Ng6 实战:https://v.qq.com/x/page/b076702elvw.html 安装工具: Nodejs, npm     最新版, h ...

  6. git 跟踪分支 远程跟踪分支 学习笔记

    远程跟踪分支相当于一个只读仓库指针,从服务器上获取数据,不可以被本地直接修改. 跟踪分支相当于一个本地指针   用于项目更新和迭代. 1跟踪分支  (tracking  branch)   逻辑示意图 ...

  7. GET请求的写法-jmeter

    第一种写法:可以向post 请求一样写 第二种写法: /pinter/com/getSku?id=${__Random(1,100,rdmNum)}

  8. HTML/JSP中一些单书名号标签的用途<%-- --%><!-- --><%@ %><%! %><% %><%= %>

    注释 <%-- --%>是(JSP)隐式注释,不会在页面显示的注释 <!-- -->是(Html)显示注释,会在JSP页面显示 关于注释还有单行隐式注释//和多行隐式注释/* ...

  9. CPU设计学习-流水线

    各种名词 标量流水线 超级流水线 超标量流水线与多发射技术 经典五级流水线 IF |Instruction Fetch,取指 ID |Instruction Decode,译码 EX |Execute ...

  10. TensorFlow | ReluGrad input is not finite. Tensor had NaN values

    问题的出现 Question 这个问题是我基于TensorFlow使用CNN训练MNIST数据集的时候遇到的.关键的相关代码是以下这部分: cross_entropy = -tf.reduce_sum ...