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 
  • 相关阅读:
    luogu P4009 汽车加油行驶问题
    luogu P4015 运输问题
    luogu P2763 试题库问题
    luogu P4011 孤岛营救问题
    luogu P2765 魔术球问题
    linux 网卡
    linux yum错误
    ubuntu登录备注信息
    Ubuntu网卡配置
    linux 走三层内网添加静态路由
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2585353.html
Copyright © 2011-2022 走看看