• B


    "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
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    //#include <unordered_set>
    //#include <unordered_map>
    #define ll              long long
    #define pii             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    #define forn(i, n)      for(int i = 0; i < int(n); i++)
    using namespace std;
    int dir[4][2] = { { 1,0 },{ 0,1 } ,{ 0,-1 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const double eps = 1e-6;
    const int mod = 1e9 + 7;
    const int N = 3e3 + 5;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    ll lcm(ll m, ll n)
    {
        return m * n / gcd(m, n);
    }
    bool prime(int x) {
        if (x < 2) return false;
        for (int i = 2; i * i <= x; ++i) {
            if (x % i == 0) return false;
        }
        return true;
    }
    ll qpow(ll m, ll k, ll mod)
    {
        ll res = 1, t = m;
        while (k)
        {
            if (k & 1)
                res = res * t % mod;
            t = t * t % mod;
            k >>= 1;
        }
        return res;
    }
    
    ll n, m;
    
    int main()
    {
        while (cin >> n)
        {
            map<int, int> mp;
            rep(i,1,n)
            {
                int t;
                cin >> t;
                mp[t]++;
            }
            int res;
            for (auto x : mp)
            {
                if (x.second >= (n + 1) / 2)
                    res = x.first;
            }
            cout << res << endl;
        }
        return 0;
    }
  • 相关阅读:
    渗透利器-kali工具 (第六章-1) 密码破解
    渗透利器-kali工具 (第五章-6) Metasploit后门生成模块
    渗透利器-kali工具 (第五章-5) Metasploit漏洞利用模块二
    渗透利器-kali工具 (第五章-4) Metasploit漏洞利用模块一
    渗透利器-kali工具 (第五章-3) Metasploit密码爆破模块
    渗透利器-kali工具 (第五章-2) Metasploit扫描漏洞模块
    渗透利器-kali工具 (第五章-1) Metasploit框架介绍与基本命令
    关于计算机网络的性能指标你需要知道这些
    写给大忙人看的计算机网络参考模型
    PHP基础编程之鬼斧神工的正则表达式-正则表达式基本语法+简单实例
  • 原文地址:https://www.cnblogs.com/dealer/p/13180729.html
Copyright © 2020-2023  润新知