hdu 1029 Ignatius ans the Princess IV

时间:2022-10-16 00:28:06

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

Problem Description
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.

"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?

 
Input
The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.
 
Output
For each test case, you have to output only one line which contains the special number you have found.
 
Sample Input
5
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
 
Sample Output
3
5
1
 
Author
Ignatius.L
 
Recommend
We have carefully selected several similar problems for you:  1040 1074 1028 1171 1087 
 
直接根据题意统计每个数出现的次数,然后输出符合条件的数就可以了
#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的更多相关文章

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

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

  2. HDU 1029 Ignatius and the Princess IV &sol; HYSBZ(BZOJ) 2456 mode(思维题,~~排序&quest;~~)

    HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...

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

  4. &lbrack;ACM&rsqb; hdu 1029 Ignatius and the Princess IV (动归或hash)

    Ignatius and the Princess IV Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32767K (Ja ...

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

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

  6. HDOJ&sol;HDU 1029 Ignatius and the Princess IV&lpar;简单DP,排序&rpar;

    此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can nev ...

  7. HDU 1029 Ignatius and the Princess IV DP

    kuangbin 专题 这题,有很多种解法. 第一种: 直接比较每个数出现次数. #include<iostream> #include<string> #include&lt ...

  8. HDU 1029 Ignatius and the Princess IV(数论)

    #include <bits/stdc++.h> using namespace std; int main(){ int n; while(~scanf("%d",& ...

  9. HDU 1029 Ignatius and the Princess IV

    解题报告: 题目大意:就是要求输入的N个数里面出现的次数最多的数是哪一个,水题.暴力可过,定义一个一位数组,先用memset函数初始化,然后每次输入一个数就将下标对应的上标对应的那个数加一,最后将整个 ...

随机推荐

  1. Jmeter 检查点

    Jmeter的检查点就是插入个断言,但用下来不好用,没LR好用,先放放.

  2. Android 程序崩溃后的处理

    在应用发布以后,由于安卓机型的千差万别 ,可能会出现各种各样的问题,这时候如果我们可以将这些信息收集起来,并进行修改就很不错了.下面就来讨论一下怎么处理程序崩溃以后,错误信息的手机. Java中已经提 ...

  3. 23种设计模式学习一(单列模式)singleton

    单列模式的类(单线程下的) class Singleton { private static Singleton instance; private Singleton() { } public st ...

  4. 给eclipse装一些插件

    最近换了一个环境,需要折腾一个新的eclipse配置,所以在这里记录下. 1.安装marketplace help=>install,输入地址:http://download.eclipse.o ...

  5. http报文在网络中是明文传输的,所以不安全。HTtp必然来临

    HTTP数据在网络中裸奔 HTTP明文协议的缺陷,是导致数据泄露.数据篡改.流量劫持.钓鱼攻击等安全问题的重要原因.HTTP协议无法加密数据,所有通信数据都在网络中明文“裸奔”.通过网络的嗅探设备及一 ...

  6. 系统数据文件和信息之附加组ID

    4.2BSD引入了附加组ID(supplementary group ID)的概念.我们不仅可以属于口令文件记录项中组ID所对应的组,也可属于多达16个另外的组.文件访问权限检查相应被修改为:不仅将进 ...

  7. Dynamics CRM 日常使用JS整理(二)

    BPF(Business Process Flow)相关的JS 为Stage添加changed或者selected事件: function fnOnLoad() { Xrm.Page.data.pro ...

  8. 用basicTrendline画一元线性回归直线的置信区间

    感慨统计学都还给老师了..恶补! R安装包的时候貌似需要用管理员权限启动,否则安装不了,国内镜像卡得渣渣,还是国外镜像真香~选择hongkong就好了. install.packages(" ...

  9. Signing package index&period;&period;&period; Cannot open file &&num;39&semi;&sol;home&sol;jello&sol;openwrt&sol;key-build&&num;39&semi; for reading

    一.环境 发行版:Ubuntu 18.04.1 LTS 代号:bionic 内核版本:4.15.0-30-generic 二.背景 在编译Openwrt/LEDE时出现以下错误,进而自动终止了编译: ...

  10. LD-sketch源码阅读

    目录 util.h hash.hpp/cpp mangle函数 GenHashSeed函数 AwareHash模块 LDSketch.hpp/cpp LDSketch更新函数,对一个sketch插入键 ...