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
     
     
  • 相关阅读:
    mybatis 查询一对多子表只能查出一条数据
    Docker 查看容器里Log4写的日 志文 件里的日志
    MYSQL之union的使用
    【前端开发】常见好用的流程图框架
    【推荐】好网站推荐
    【前端工具】好用的数据库工具Navicat
    jQuery ajax
    thinkphp6.0封装数据库及缓存模型
    Unity 3D使用C#脚本实例
    Unity 3D简单使用C#脚本,脚本的执行顺序
  • 原文地址:https://www.cnblogs.com/cyd308/p/4492573.html
Copyright © 2011-2022 走看看