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
     
     
  • 相关阅读:
    msql查询指定日期
    NLP常见任务
    KTT条件及其理解
    距离度量--熵,KL散度,JS散度,GAN相关应用
    常见的激活函数
    分类问题的判别标准
    最大似然估计
    损失函数
    【ML-10】多分类及多标签分类算法
    【ML-9】支持向量机--实验scitit-learn SVM
  • 原文地址:https://www.cnblogs.com/cyd308/p/4492573.html
Copyright © 2011-2022 走看看