zoukankan      html  css  js  c++  java
  • 【Ignatius and the Princess IV 专题训练排序】

     Ignatius and the Princess IV
    Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d & %I64u
    Appoint description: 

    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
     
     
     1 // Project name : A ( Ignatius and the Princess IV ) 
     2 // File name    : main.cpp
     3 // Author       : Izumu
     4 // Date & Time  : Tue Jul 10 21:28:58 2012
     5 
     6 
     7 #include <iostream>
     8 #include <stdio.h>
     9 #include <string>
    10 #include <cstring>
    11 #include <cmath>
    12 #include <algorithm>
    13 using namespace std;
    14 
    15 int a[32769];
    16 int n;
    17 int temp;
    18 
    19 int main()
    20 {
    21     int n;
    22     while (scanf("%d", &n) != EOF)
    23     {
    24         memset(a, 0, sizeof(a));
    25         
    26         int max = 0;
    27         int flag = -1;
    28         for (int i = 0; i < n; i++)
    29         {
    30             scanf("%d", &temp);
    31             a[temp]++;
    32             if (a[temp] > max)
    33             {
    34                 flag = temp;
    35                 max  = a[temp];
    36             }
    37         }
    38         
    39         printf("%d\n", flag);
    40     }
    41     
    42     return 0;
    43 }
    44 
    45 // end 
    46 // ism 
  • 相关阅读:
    基于mini2440的boa服务器移植
    主机+虚拟机ubuntu+mini2440开发板互相ping通
    poj3133 插头dp
    2015 北京网络赛 E Border Length hihoCoder 1231 树状数组 (2015-11-05 09:30)
    2015 北京网络赛 C Protecting Homeless Cats hihoCoder 1229 树状数组
    acm 2015北京网络赛 F Couple Trees 主席树+树链剖分
    hdu4777 树状数组
    hdu5517 二维树状数组
    Codeforces Round #327 (Div. 1) D. Top Secret Task
    2014-2015 ACM-ICPC, Asia Xian Regional Contest GThe Problem to Slow Down You
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2585353.html
Copyright © 2011-2022 走看看