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 
  • 相关阅读:
    ue父子组件的数据传递示例
    vue.js 组件之间传递数据
    Vue2.0子同级组件之间数据交互
    assets 和static的区别
    Vue中src属性绑定的问题
    css3设置背景图片的大小
    如何在HTML中插入空格
    css背景图片的设置
    vue动态组件 互相之间传输数据 和指令的定义
    webservice的优缺点
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2585353.html
Copyright © 2011-2022 走看看