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
     
     
  • 相关阅读:
    Aurora 数据库支持多达五个跨区域只读副本
    Amazon RDS 的 Oracle 只读副本
    Amazon EC2 密钥对
    DynamoDB 读取请求单位和写入请求单位
    使用 EBS 优化的实例或 10 Gb 网络实例
    启动 LAMP 堆栈 Web 应用程序
    AWS 中的错误重试和指数退避 Error Retries and Exponential Backoff in AWS
    使用 Amazon S3 阻止公有访问
    路由表 Router Table
    使用MySQLAdmin工具查看QPS
  • 原文地址:https://www.cnblogs.com/cyd308/p/4492573.html
Copyright © 2011-2022 走看看