Ignatius and the Princess IV

点我跳转到题面

点我一起学习STL-MAP

题意分析

给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出。

用map做出映射,然后迭代器检查是否满足输出条件,是的话输出即可。

代码总览

  1. /*
  2. Title:HDOJ.1029
  3. Author:pengwill
  4. Date:2016-11-21
  5. */
  6. #include <iostream>
  7. #include <stdio.h>
  8. #include <map>
  9. using namespace std;
  10. typedef map<int,int> mp;
  11. mp p;
  12. int main()
  13. {
  14. int n,temp,t;
  15. while(scanf("%d",&n)!= EOF){
  16. t = n;
  17. while(n--){
  18. scanf("%d",&temp);
  19. p[temp]++;
  20. }
  21. mp::iterator iter;
  22. temp = 1;
  23. for(iter = p.begin();iter!=p.end();iter++){
  24. //cout<<iter->first<<"\t"<<iter->second<<endl;
  25. if(iter->second >= ((t+1)/2)){
  26. printf("%d\n",iter->first);
  27. break;
  28. }
  29. }
  30. p.clear();
  31. }
  32. return 0;
  33. }

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. Qt-第一个QML程序-3-自定义一个按钮

    项目基本信息前两个已经说了,这里直接放下运行截图, 对的,这里就是说上面的那个红色的按钮,这里需要了解Qml的动画和状态 这里先把整个按钮的代码写出来,一点一点写 Rectangle { id:clo ...

  2. RabbitMQ基础教程之使用进阶篇

    RabbitMQ基础教程之使用进阶篇 相关博文,推荐查看: RabbitMq基础教程之安装与测试 RabbitMq基础教程之基本概念 RabbitMQ基础教程之基本使用篇 I. 背景 前一篇基本使用篇 ...

  3. Java开发工程师(Web方向) - 01.Java Web开发入门 - 第5章.Git

    第5章--Git 版本控制简介 VCS (version control system) 版本控制系统:记录若干文件的修订记录的系统,帮助查阅/回到某个历史版本 LVCS本地 CVCS集中式(Cent ...

  4. Git命令使用大全

    一前言 最近公司在使用vue和WebAPI前后端分离的项目开发,使用的代码管理工具是git,刚开始使用的时候前端的vue文件还比较好处理,但是后端的C#文件在每一次自己编译之后上传都会和其他小伙伴的代 ...

  5. python numpy数据相减

    numpy数据相减,a和b两者shape要一样,然后是对应的位置相减.要不然,a的shape可以是(1,m),注意m要等于b的列数. import numpy as np a = [ [0, 1, 2 ...

  6. Python字符串格式化表达式和格式化方法

    Python格式化字符串由两种方式可以选择:一种是格式化表达式(Formatting Expression),一种是格式化方法(Formatting Method).其中格式化表达式在全Python版 ...

  7. c# 读取xml文件 编写form

    主要思想:xml保存控件的数据,c#读取出来并加以显示. 难点:1.控件有父容器和子控件的关系:2.控件事件的添加. 1.控件有父容器和子控件的关系: 可以用绝对坐标在xml文件中先读取子控件再读取父 ...

  8. P4语法(2) Parser

    这里参考学习了: P4语言规范 P4台湾社群 Parser 关于parser 在P4程序中,有着大量的首部(header)和首部实例,但每次只有部分首部实例会对数据包进行操作,而parser会用于生成 ...

  9. Java微笔记(2)

    Java 中方法的重载 一,如果同一个类中包含了两个或两个以上方法名相同.方法参数的个数.顺序或类型不同的方法,则称为方法的重载,也可称该方法被重载了 二,.判断方法重载的依据: 1. 必须是在同一个 ...

  10. phpcmsv9 同时调用多个栏目的文章标签

    V9版本默认好像没有多栏目调用的标签,例如我用{pc:content action="lists" catid ="6,7,8,9,10" num=" ...