Ignatius and the Princess IV HDU 1029
题目大意: 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的更多相关文章
- Ignatius and the Princess IV HDU - 1029 基础dp
#include<iostream> #include<cstring> #include<cmath> #include<cstdio> #inclu ...
- HDU 1029 Ignatius and the Princess IV --- 水题
HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出 ...
- 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 ...
- 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 ...
- hdu 1029 Ignatius ans the Princess IV
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- [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 ...
- HDU 1029 Ignatius and the Princess IV (动态规划、思维)
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- 【HDU - 1029】Ignatius and the Princess IV (水题)
Ignatius and the Princess IV 先搬中文 Descriptions: 给你n个数字,你需要找出出现至少(n+1)/2次的数字 现在需要你找出这个数字是多少? Input ...
- HDOJ.1029 Ignatius and the Princess IV(map)
Ignatius and the Princess IV 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出. ...
随机推荐
- Partition Array into Disjoint Intervals
2020-02-10 22:16:50 问题描述: 问题求解: 解法一:MultiSet O(nlog) 看了下数据规模,第一个想到的是multiset,肯定可以ac的,就直接敲了出来. public ...
- BIT-逆序数
2019-12-17 09:42:44 问题描述: 问题求解: 逆序数问题非常经典,使用树状数组可以高效的解决这个问题. public List<Integer> countSmaller ...
- [BFS]Codeforces Igor In the Museum
Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 面试刷题21:java并发工具中的队列有哪些?
; function IEVersion() { var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var is ...
- 爬虫scrapy框架的使用
第一步 下载scrapy模块: pip install scrapy 第二步 创建项目 在终端/cmd进入创建项目的目录:scrapy startproject douban(项目名) 导入pycha ...
- Pytest系列(5) - 用例执行的几种状态
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 用例执行状态 用例执行完成后,每条 ...
- 牛客寒假基础集训营 | Day1 D-hanayo和米饭
D-hanayo和米饭 题目描述 hanayo很喜欢吃米饭. 有一天,她拿出了 nnnnnnnnn 个碗,第一个碗装了 111111111 粒米饭,第二个碗装了 222222222 粒米饭,以此类推, ...