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 
  • 相关阅读:
    Prometheus入门教程(二):Prometheus + Grafana实现可视化、告警
    Prometheus 入门教程(一):Prometheus 快速入门
    Prometheus 系列开篇:为什么要学 Prometheus ?
    你总是遗憾,是因为你还没想好,你的一生想怎么过!
    搞 Java 的年薪 40W 是什么水平?
    闪送,为何能从顺丰中杀出一条血路?
    安全攻击溯源思路及案例
    Windows下登录凭证窃取技巧
    Linux下登录凭证窃取技巧
    如何探测内网存活主机
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2585353.html
Copyright © 2011-2022 走看看