hdu 1029 Ignatius ans the Princess IV
Ignatius and the Princess IV
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 27227    Accepted Submission(s): 11562
"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?
1 3 2 3 3
11
1 1 1 1 1 5 5 5 5 5 5
7
1 1 1 1 1 1 1
5
1
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
map <int,int> num;
int main()
{
int n;
while(~scanf("%d",&n))
{
num.clear();
for(int i=;i<n;i++)
{
int tmp;
scanf("%d",&tmp);
num[tmp]++;
}
int times= (n+)/;
int ans= 0x3ffffff;
map<int,int>::iterator iter;
for(iter=num.begin();iter!=num.end();iter++)
{
if(iter->second>=times) ans= iter->first;
}
printf("%d\n",ans);
}
}
hdu 1029 Ignatius ans 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 ...
 - [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 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",& ...
 - HDU 1029 Ignatius and the Princess IV
		
解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...
 
随机推荐
- Java for LeetCode 231 Power of Two
			
public boolean isPowerOfTwo(int n) { if(n<1) return false; while(n!=1){ if(n%2!=0) return false; ...
 - nyoj20_吝啬的国度_DFS
			
吝啬的国度 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市, ...
 - [Android进阶]学习AccessibilityService实现微信抢红包插件
			
在你的手机更多设置或者高级设置中,我们会发现有个无障碍的功能,很多人不知道这个功能具体是干嘛的,其实这个功能是为了增强用户界面以帮助残障人士,或者可能暂时无法与设备充分交互的人们 它的具体实现是通过A ...
 - 编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值
			
编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值 1 #import <Foundation/Foundation.h> 2 3 int main( ...
 - 用java套接字创建HTTP客户与服务器程序
			
最近再学习java的web编程,发现用java创建一个小的服务器和客户端是如此的简单,引用经典图书<Tomcat与Java Web开发技术详解(第二版)>(孙卫琴) 根据书中案例敲代码自己 ...
 - ios wax热更新之安装wax(xcode7.3.1)
			
通过Finder浏览到你保存该项目的文件夹.创建三个新的文件夹:wax.scripts和Classes. 第一:首先,下载源代码的压缩包.Wax放在GitHub上(https://github.com ...
 - 奶牛健美操(codevs 3279)
			
题目描述 Description Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的小路上奔跑.这些奶牛的路径集合可以被表示成一个点集和一些连接 两个顶点的双向路,使得每对点 ...
 - 利用 Rational ClearCase ClearMake 构建高性能的企业级构建环境
			
转载地址:http://www.ibm.com/developerworks/cn/rational/r-cn-clearmakebuild/ 构建管理是 IBM® Rational® ClearCa ...
 - Git的一些实用操作
			
Ref:http://stackoverflow.com/questions/17195861/undo-git-update-index-assume-unchanged-file 1. 添加本地忽 ...
 - hibernate之处理视图
			
近期,我去用hibernate去创建视图, 发现无法进立建立视图, 为啥? 个人去尝试去,却发现无法很好的完成, 因为hibernate的作用类似视图 后解决方案是: 1.用传统的方式去处理 2.写存 ...