HDU B-Ignatius and the Princess IV
http://acm.hdu.edu.cn/showproblem.php?pid=1029
"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.
"But what is the characteristic of the special integer?" Ignatius asks.
"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.
Can you find the special integer for Ignatius?
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e6 + 10;
int N;
int num[maxn], cnt[maxn]; int main() {
while(~scanf("%d", &N)) {
memset(num, 0, sizeof(num));
memset(cnt, 0, sizeof(cnt)); if(!N) break; for(int i = 1; i <= N; i ++) {
scanf("%d", &num[i]);
cnt[num[i]] ++;
} int temp;
for(int i = 1; i <= N; i ++) {
if(cnt[num[i]] >= (N + 1) / 2) {
temp = num[i];
}
}
printf("%d\n", temp);
}
return 0;
}
HDU B-Ignatius and the Princess IV的更多相关文章
- 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 ( ...
- HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)
此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can nev ...
- HDU 1029 Ignatius and the Princess IV
解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...
- HDU 1029 Ignatius and the Princess IV DP
kuangbin 专题 这题,有很多种解法. 第一种: 直接比较每个数出现次数. #include<iostream> #include<string> #include< ...
- HDU 1029 Ignatius and the Princess IV(数论)
#include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...
随机推荐
- jwplayer 参数记录
jwplayer().getPosition()://播放了多少秒 jwplayer('playerdiv').play(); || jwplayer(0).play(true/false); // ...
- Linux入门-第六周
1.总结IP地址规划 IP地址的合理规划是网络设计中最重要的一环,在大型网络中必须对IP地址进行统一规划并得到实施.IP地址规划的好坏影响到网络路由协议算法的效率,影响到网络的性能,影响到网络的拓展, ...
- 路由器基础配置之ospf基础配置
我们将以上面的拓扑图进行本次ospf的实验,目的是能当三台pc机互通 先配置好pc机的IP地址,注意一定要给pc机设置好网关,接下来配置路由器的IP地址 router4 enable 进入特权模式 c ...
- ubuntu如何设置Python的版本
Ubuntu默认已经安装了Python的版本了,不过是Python2的版本. 我们安装好Python3想把他切换为系统默认的版本. sudo update-alternatives --config ...
- c# WebBrowser开发参考资料--杂七杂八
c# WebBrowser开发参考资料 http://hi.baidu.com/motiansen/blog/item/9e99a518233ca3b24aedbca9.html=========== ...
- HDU1209:Clock
参考:https://blog.csdn.net/libin56842/article/details/8990530 https://blog.csdn.net/u011479875/article ...
- [Cracking the Coding Interview] 4.2 Minimal Tree 最小树
Given a sorted(increasing order) array with unique integer elements, write an algorithm to create a ...
- Javaweb——四则运算---18.11.01
---恢复内容开始--- test.jsp <%@ page language="java" contentType="text/html; charset=utf ...
- git 本地分支与远程分支 新建/删除/合并
github上已经有master分支 和dev分支 在本地 git checkout -b dev 新建并切换到本地dev分支 git pull origin dev 本地分支与远程分支相关联 在本地 ...
- 4368: [IOI2015]boxes纪念品盒
4368: [IOI2015]boxes纪念品盒 链接 分析 链接 代码 #include<bits/stdc++.h> using namespace std; typedef long ...