Ignatius and the Princess IV

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)

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

题意:给奇数个数字,找一个至少出现了 (n+1)/2次的特殊数字。

题解:一道水题,用好 (n+1)/2就可以,看代码。~(其实只要排一次序,然后直接输出中间那个数就可以)~

#include <iostream>
#include <cstdio> using namespace std; int main()
{
int n,num,a,x,i;
while(scanf("%d",&n)!=EOF)
{
num = 0;
for(i=0;i<n;i++)
{
scanf("%d",&a);
if(!num)
{
num = 1;
x = a;
}
else
{
if(a==x)
num++;
else
num--;
}
}
cout<<x<<endl;
}
return 0;
}

HDU-1029_Ignatius and the Princess IV的更多相关文章

  1. HDU 1029Ignatius and the Princess IV

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

  2. HDU B-Ignatius and the Princess IV

    http://acm.hdu.edu.cn/showproblem.php?pid=1029 Problem Description "OK, you are not too bad, em ...

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

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

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

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

  6. hdu 1029 Ignatius ans the Princess IV

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

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

  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 and the Princess IV (水题)

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

  10. (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 ...

随机推荐

  1. JavaScript内容回顾

    <!DOCTYPE html> <!--JavaScript内容回顾--> <html lang="en"> <head> < ...

  2. CSS3的transform 转换

    transform是可以实现元素位移,旋转,缩放和变形.只介绍了2D转换~ translate 位移:改变元素位置 最多设置两个值,一个水平,一个垂直.如果设置为负数,则代表反方向.可设置百分比.eg ...

  3. 使用 WPF 生成图形

    下载代码示例 基于一组与测试有关的数据来生成图形是一项常见的软件开发任务.根据我的经验,最常用的方法是将数据导入 Excel 电子表格,然后使用 Excel 内置的绘图功能手动生成图形.这种做法适用于 ...

  4. golang redis_example

    main.go package main import ( "fmt" "github.com/garyburd/redigo/redis" ) func ma ...

  5. pycharm中引入相对路径错误

    真是气死老子了,明明代码就在眼前,居然pycharm说找不到,import报错,最后才发现,需要设置代码的根目录,因此,python代码就在app目录下面,故将app设置成代码根目录就行了

  6. C#中Object转化为json对象

    比如定义一个类: public class Lines { public string X1 { get; set; } public string X2 { get; set; } public s ...

  7. 模拟退火解TSP问题MATLAB代码

    分别把前四个函数存成m文件,再运行最后一个. swap.m function [ newpath , position ] = swap( oldpath , number ) % 对 oldpath ...

  8. springboot-mybatis双数据源配置

    yml文件 spring: datasource: test1: driverClassName: com.mysql.jdbc.Driver url: jdbc:mysql://localhost: ...

  9. Web学习之跨域问题及解决方案

    在做前端开发时,我们时常使用ajax与服务器通信获取资源,享受ajax便利的同时,也知道它有限制:跨域安全限制,即同源策略. 同源策略(SOP),核心是确保不同源提供的文件之间是相互独立的 默认情况下 ...

  10. java jsp j2ee

    1. JavaScript用于编写嵌入在网页文档中的程序,它由浏览器负责解释和执行,可以在网页上产生动态的显示效果和实现与用户交互的功能,譬如,让一串文字跟着鼠标移动,让一个图标在网页漂浮移动,验证用 ...