"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

题解:刷访问量,此题太简单

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring> using namespace std; int main()
{
int n;
int dp[100005]={0};
while(scanf("%d",&n)!=EOF)
{
memset(dp,0,sizeof(dp));
int flag=0;
int k;
for(int t=0;t<n;t++)
{
scanf("%d",&k);
dp[k]++;
if(dp[k]>=(n+1)/2)
{
if(flag==0)
printf("%d\n",k);
flag=1;
}
}
}
}

Ignatius and the Princess IV (水题)的更多相关文章

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

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

  2. HDU1029 Ignatius and the Princess IV (水题)

    <题目链接> 题目大意:给你一段序列,问你在这个序列中出现次数至少为 (n+1)/2 的数是哪个. 解题分析: 本题是一道水题,如果用map来做的话,就非常简单,但是另一个做法还比较巧妙. ...

  3. kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)

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

  4. 【HDU - 1029】Ignatius and the Princess IV (水题)

    Ignatius and the Princess IV  先搬中文 Descriptions:   给你n个数字,你需要找出出现至少(n+1)/2次的数字 现在需要你找出这个数字是多少? Input ...

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

  6. (Arrays.sort() 或 map) Ignatius and the Princess IV hdu1029

    Ignatius and the Princess IV 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 借鉴链接:https://blog.csd ...

  7. HDOJ.1029 Ignatius and the Princess IV(map)

    Ignatius and the Princess IV 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出一个奇数n,下面有n个数,找出下面数字中出现次数大于(n+1)/2的数字,并输出. ...

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

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

  9. hdu 1029 Ignatius ans the Princess IV

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

  10. Ignatius and the Princess IV

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

随机推荐

  1. linux查询操作系统信息,CPU物理个数,CPU核心数,逻辑CPU数,内存信息查询,硬盘信息查询

    目录 一.前言 二.关于服务器基本配置 2.1 操作系统基本配置查询 2.2 CPU基本配置查询 2.3 内存基本配置查询 2.4 硬盘基本配置查询 一.前言 ​ 当我们接手了一台或者几台服务器的时候 ...

  2. Springboot+swagger2.7集成开发

    Springboot+swagger2.7集成开发 本篇文章是介绍最新的springboot和swagger2.7集成开发和2.0稍微有一些出入: Springboot集成环境配置 Swagger2. ...

  3. 团队项目-记账App

    一.团队成员介绍 队长: 向瑜 博客园地址: https://www.cnblogs.com/xiangyu721/  沟通能力较强,善于总结,能够正确分配团队任务.其次,有耐心学习新事物,发现新问题 ...

  4. Python分析「我们为什么这么穷」

  5. JS 前端框架笔记

    Swiper轮播图插件使用     官网:https://www.swiper.com.cn/     先引用插件的css.js文件     然后找到需要使用的轮播图文件中去把HTML css和JS代 ...

  6. SpringBoot介绍,快速入门小例子,目录结构,不同的启动方式,SpringBoot常用注解

    SpringBoot介绍 引言 为了使用ssm框架去开发,准备ssm框架的模板配置 为了Spring整合第三方框架,单独的去编写xml文件 导致ssm项目后期xml文件特别多,维护xml文件的成本也是 ...

  7. 面向对象的js编程 Call和apply方法

    JavaScript中有一个call和apply方法,其作用基本相同,但也有略微的区别. 一.方法定义 1.call 方法 语法:call([thisObj[,arg1[, arg2[, [,.arg ...

  8. C#LeetCode刷题之#704-二分查找(Binary Search)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3999 访问. 给定一个 n 个元素有序的(升序)整型数组 num ...

  9. C#设计模式之0-简单工厂模式

    简单工厂模式(Simple Factory Pattern) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/387 访问 ...

  10. JavaScript async/await 基础知识

    async 作用: async函数返回一个 Promise对象,无论内部有没有await关键字. await 作用: await等待的是一个表达式,这个表达式的计算结果是 Promise 对象 或者是 ...