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 }
  • 相关阅读:
    P4141 消失之物(退背包模板)
    P5829 【模板】失配树
    P4827 [国家集训队] Crash 的文明世界
    P4074 [WC2013]糖果公园
    P3242 [HNOI2015]接水果
    P2371 [国家集训队]墨墨的等式
    P4819 [中山市选]杀人游戏
    P5331 [SNOI2019]通信
    BZOJ1082 [SCOI2005]栅栏
    poj1475 Pushing Boxes[双重BFS(毒瘤搜索题)]
  • 原文地址:https://www.cnblogs.com/CuteAbacus/p/9487949.html
Copyright © 2011-2022 走看看