zoukankan      html  css  js  c++  java
  • Ignatius and the Princess IV

    Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d & %I64u

    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.
     1 #include<stdio.h>
     2 #include<string.h>
     3 
     4 int main()
     5 {
     6     int i,j;
     7     int N,num;
     8     int x,cas;
     9     while(scanf("%d",&N)!=EOF)
    10     {
    11         num=0;
    12         for(i=1;i<=N;i++)
    13         {
    14             scanf("%d",&cas);
    15             if(num==0)
    16             {
    17                 x=cas;
    18                 num++;
    19             }
    20             else
    21             {
    22                 if(x==cas)
    23                     num++;
    24                 else
    25                     num--;
    26             }
    27         }
    28         printf("%d
    ",x);
    29     }
    30     return 0;
    31 }
    View Code

    2.

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<algorithm>
     4 using namespace std;
     5 int a[1000005];
     6 int main()
     7 {
     8     int i,j,N;
     9 
    10     while(scanf("%d",&N)!=EOF)
    11     {
    12         for(i=0;i<N;i++)
    13             scanf("%d",&a[i]);
    14         sort(a,a+N);
    15         printf("%d
    ",(a[(N-1+1)/2]));
    16     }
    17     return 0;
    18 }
    View Code
     
     
  • 相关阅读:
    [SDOi2012]Longge的问题(洛谷 2303)
    Biorhythms(信息学奥赛一本通 1639)
    【NOI2002】荒岛野人(信息学奥赛一本通 1637)(洛谷 2421)
    青蛙的约会(信息学奥赛一本通 1631)(洛谷 1516)
    负数求余究竟怎么求???
    X-factor Chain(信息学奥赛一本通 1628)
    同余问题2(超详细!!!)
    map函数怎么用咧↓↓↓
    同余问题1(超详细!!!)
    python -- 连接 orclae cx_Oracle的使用 二
  • 原文地址:https://www.cnblogs.com/cyd308/p/4492573.html
Copyright © 2011-2022 走看看