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",& ...
随机推荐
- Hibernate知识点小结(三)-->一对多与多对多配置
一.多表关系与多表设计 1.多表关系 一对一: 表的设计原则(分表原则): 优化表的性能 基于语意化分表 ...
- JAVA如何跨项目调用接口
public String load(String url, String query) throws Exception { URL restURL = new URL(url); /* * 此处的 ...
- poj_2249_Binomial Showdown
In how many ways can you choose k elements out of n elements, not taking order into account? Write a ...
- Java反射的两种使用方法
1.创建User.java package com.tao.test; public class User { private String name; private int id; public ...
- Co. - Apple - MacBook Pro 快捷键
Mac 键盘快捷键:https://support.apple.com/zh-cn/HT201236 从windows转到mac的童鞋,可能删除键是心中的一个痛,以前习惯一按delete什么都消失,其 ...
- css实现下拉菜单功能(多中实现方式即原理)
引导思路: 1.需要用到的元素:position hover (z-index) 或(overflow)或(display)等等. 关键点就是div的溢出部分的处理. 2.实现过程: 2.1:就是要 ...
- JavaScript : CORS和Ajax请求
CORS(Cross-Origin Resource Sharing, 跨源资源共享)是W3C出的一个标准,其思想是使用自定义的HTTP头部让浏览器与服务器进行沟通,从而决定请求或响应是应该成功,还是 ...
- angularjs路由不断刷新当前页面
最近做项目遇到个问题,使用angular-route的时候,第一次点击 [按钮 a]会进入按钮a对应的控制器,接着再次点击a按钮的的时候就不会进入控制器了.我想要的效果是每次点击都能进入control ...
- Hadoop启动后无法启动NodeManager
在配置完Hadoop集群后,使用命令:“start-all.sh”进行启动集群.然后使用命令:“jps”查看进程启动情况,发现没有NodeManager 只需要使用命令:cd /usr/local/ ...
- 安装和配置Sentry(收录)
安装和配置Sentry 本文主要记录安装和配置Sentry的过程,关于Sentry的介绍,请参考 Apache Sentry架构介绍 . 1. 环境说明 系统环境: 操作系统:CentOs 6.6 H ...