HDOJ 1026 Ignatius and the Princess I

Ignatius and the Princess IV

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 34530    Accepted Submission(s): 15051

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



#include <cstdio>
#include <algorithm>
using namespace std;
int a[1000001];

int main()
{
    int n;
    while(~scanf("%d",&n)) //!!!不加会超时
        {                  // ~  !=EOF
            for(int i=0;i<n;i++)
                scanf("%d",&a[i]);
            sort(a+1,a+n+1);
            printf("%d\n",a[(n+1)/2]);  //巧妙之处
        }
    return 0;
}

 
时间: 2024-11-03 22:52:01

HDOJ 1026 Ignatius and the Princess I的相关文章

hdoj 1026 Ignatius and the Princess I 【BFS】

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12750    Accepted Submission(s): 4034 Special Judge Problem Description The Princess has been abducted by the BEelzeb

HDU 1026 Ignatius and the Princess I (基本算法-BFS)

Ignatius and the Princess I Problem Description The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castle. The castle is a large labyrinth. To make the problem si

HDU 1026 Ignatius and the Princess I 迷宫广搜剪枝问题

本题是个经典的迷宫广搜问题类型了.网上看到好多解法. 很多解题报告都没什么分析,更不会指出其中的关键点.代码更加像一大抄.有人分析也一大篇分析,不过全部都不切中关键,甚至在分析什么广搜和深搜区别,广搜为什么快之类的,还有喊什么暴搜之类的,全错了.估计这些代码都是抄过的. 通过一大段的时间研究,终于搞通了. 本题虽然可以说是广搜,但是其中的关键却是剪枝法,为什么呢? 因为迷宫并不能简单地广搜就能搜索出所有路径的,甚至只要迷宫大点就不能搜索出是否有路径,如果没有条件剪枝的情况下:不信,你严格写一个广

hdu 1026 Ignatius and the Princess I (BFS+优先队列)

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11700    Accepted Submission(s): 3653Special Judge Problem Description The Princess has been abducted by the BEelzebub

HDU 1026 Ignatius and the Princess I(BFS+路径输出)

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19800    Accepted Submission(s): 6452Special Judge Problem Description The Princess has been abducted by the BEelzebub

hdoj 1027 Ignatius and the Princess II 【逆康托展开】

Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4865    Accepted Submission(s): 2929 Problem Description Now our hero finds the door to the BEelzebub feng5166. He o

HDOJ 1027 Ignatius and the Princess II - next_permutation函数

Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5447    Accepted Submission(s): 3198 Problem Description Now our hero finds the door to the BEelzebub feng5166. He o

HDU - 1026 Ignatius and the Princess I

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Special Judge Problem Description The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Prin

hdu 1026 Ignatius and the Princess I 广搜+优先队列+记录路径

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13414    Accepted Submission(s): 4232 Special Judge Problem Description The Princess has been abducted by the BEelzeb