zoukankan      html  css  js  c++  java
  • Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题

    B. Alyona and Mex

    题目连接:

    http://www.codeforces.com/contest/682/problem/B

    Description

    Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.

    Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.

    Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.

    The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

    Output

    Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.

    Sample Input

    5
    1 3 3 3 6

    Sample Output

    5

    Hint

    题意

    给你一个序列,然后这个序列可以交换任意两个数的位置,以及减小若干个数的大小。

    然后问你这个序列的mex最大能够是多少。

    题解:

    排序扫一遍,太水了……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e5+7;
    int n,a[maxn];
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        sort(a+1,a+1+n);
        int level=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]>level)
                level++;
        }
        cout<<level+1<<endl;
    }
  • 相关阅读:
    逆向与BOF基础——注入shellcode并执行&Return-to-libc
    20145304 网络对抗技术 逆向与Bof基础
    20145303刘俊谦 《网络对抗》Exp9 Web安全基础实践
    操作系统取证实践
    20145303刘俊谦 Exp8 Web基础
    20145303刘俊谦 Exp7 网络欺诈技术防范
    20145303《网络对抗》信息收集和漏洞扫描技术
    20145303刘俊谦《网络攻防》Exp4 Msf基础
    msf辅助模块的应用
    Adobe漏洞攻击
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5595681.html
Copyright © 2011-2022 走看看