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 }
  • 相关阅读:
    局部地区类似淘宝设想
    eclipse中安装GWT插件
    MYSQL数据库设计和数据库设计实例(三)
    MYSQL数据库设计和数据库设计实例(二)
    微软万维天文望远镜(Microsoft World Wide Telescope)
    html学习列表
    java中多线程学习一二点
    win7 64位下完美安装64位oracle 11g
    eclipse运行时不能自动保存的解决方法
    MYSQL数据库设计和数据库设计实例(一)
  • 原文地址:https://www.cnblogs.com/CuteAbacus/p/9487949.html
Copyright © 2011-2022 走看看