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
     
     
  • 相关阅读:
    BZOJ 1818: [Cqoi2010]内部白点 扫描线+树状数组
    BZOJ 2091: [Poi2010]The Minima Game 博弈dp
    BZOJ 4459: [Jsoi2013]丢番图 数学推导
    BZOJ 3561: DZY Loves Math VI 莫比乌斯反演+复杂度分析
    BZOJ 3048: [Usaco2013 Jan]Cow Lineup 双指针
    PAT Basic 1012 数字分类 (20 分)
    PAT Basic 1008 数组元素循环右移问题 (20 分)
    大数据数据库HBase(一)——架构原理
    PAT Basic 1046 划拳 (15 分)
    PAT Basic 1026 程序运行时间 (15 分)
  • 原文地址:https://www.cnblogs.com/cyd308/p/4492573.html
Copyright © 2011-2022 走看看