题目大意: n个数字,找出其中至少出现(n+1)/2次的数字,并且保证n是奇数.

题解:这道题数组是不能用的,因为题目没有明确输入的数据范围,比如输入了一个1e9,数组肯定开不了这么大。所以要用map来记录每个数字出现的次数,边输入边记录,然后找到满足题意的数即可。

code:

#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
mp.clear();
int x,tmp=(n+)/,ans;
for(int i=;i<=n;i++){
scanf("%d",&x);
mp[x]++;
if(mp[x]>=(n+)/) {
ans=x;
}
}
printf("%d\n",ans);
}
return ;
}

Ignatius and the Princess IV HDU 1029的更多相关文章

  1. Ignatius and the Princess IV HDU - 1029 基础dp

    #include<iostream> #include<cstring> #include<cmath> #include<cstdio> #inclu ...

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

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

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

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

  5. hdu 1029 Ignatius ans the Princess IV

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

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

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

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

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

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

  9. HDOJ.1029 Ignatius and the Princess IV(map)

    Ignatius and the Princess IV 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出. ...

随机推荐

  1. Partition Array into Disjoint Intervals

    2020-02-10 22:16:50 问题描述: 问题求解: 解法一:MultiSet O(nlog) 看了下数据规模,第一个想到的是multiset,肯定可以ac的,就直接敲了出来. public ...

  2. BIT-逆序数

    2019-12-17 09:42:44 问题描述: 问题求解: 逆序数问题非常经典,使用树状数组可以高效的解决这个问题. public List<Integer> countSmaller ...

  3. [BFS]Codeforces Igor In the Museum

     Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. 面试刷题21:java并发工具中的队列有哪些?

    ![image.png](https://img2020.cnblogs.com/other/268922/202003/268922-20200330183801141-1514127119.png ...

  5. Linux上通过docker方式安装mysql

    centos版本信息: docker版本信息 mysql版本:5.7 1.docker方式安装 首先拉取mysql镜像:docker pull mysql:5.7     查看本地的mysql镜像 执 ...

  6. JavaScript超越了Java,c,python等等成为Stack Overflow上最热门的

    JavaScript超越了Java,c,python等等成为Stack Overflow上最热门的标签 在2015年6月至今,JavaScript超越了Java,c,python等等成为Stack O ...

  7. coding++ :JS-判断当前是否是IE浏览器,并返回时IE几?

    IEVersion(); function IEVersion() { var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var is ...

  8. 爬虫scrapy框架的使用

    第一步 下载scrapy模块: pip install scrapy 第二步 创建项目 在终端/cmd进入创建项目的目录:scrapy startproject douban(项目名) 导入pycha ...

  9. Pytest系列(5) - 用例执行的几种状态

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 用例执行状态 用例执行完成后,每条 ...

  10. 牛客寒假基础集训营 | Day1 D-hanayo和米饭

    D-hanayo和米饭 题目描述 hanayo很喜欢吃米饭. 有一天,她拿出了 nnnnnnnnn 个碗,第一个碗装了 111111111 粒米饭,第二个碗装了 222222222 粒米饭,以此类推, ...