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

    题目
    "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? 

    InputThe 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. 
    OutputFor 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 /*******************************************
     2  *    dp挑战二     相信自己!! 加油
     3  *  2018/8/15    19:45 
     4  *******************************************/
     5  
     6 /*******************************************
     7  * 这仿佛不用dp也能写的样子 
     8  *******************************************/
     9 #include<iostream>
    10 #include<map>
    11 using namespace std;
    12 int a[1000000];
    13 int main(){
    14      int n;
    15      while(cin>>n){
    16          int num=0;
    17          int ans;
    18          for(int i=0;i<n;i++){
    19              cin>>a[i];
    20          }
    21          for(int i=0;i<n;i++){
    22              if(num==0){
    23                  ans=a[i];
    24                  num++;
    25              }
    26              else if(a[i]==ans)num++;
    27              else num--;
    28          }
    29          cout<<ans<<endl;
    30      }
    31      return 0;
    32 }
  • 相关阅读:
    Linux crontab 命令
    tcpdump抓包工具
    tcpdump过滤某个端口
    ARM处理器基础Cortex-M4
    rtems floating poing switch
    ARM处理器的堆栈和函数调用,以及与Sparc的比较
    关于调用堆栈,任务堆栈
    如何测试嵌入式处理器的CPU使用率
    关于嵌入式实时操作系统的实时性
    RTEMS API
  • 原文地址:https://www.cnblogs.com/CuteAbacus/p/9487949.html
Copyright © 2011-2022 走看看