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;
    }
  • 相关阅读:
    JavaScript 相等(==)与全等(===)操作符
    JavaScript 判断空对象、空数组的方法
    JavaScript中的深拷贝与浅拷贝
    JS trim去除字符串收尾指定字符
    Django+Markdown+Pygments 支持Markdown 实现代码高亮
    crontab 定时服务
    程序员如何修复婚姻的bug
    向Mysql 中插入汉字(Emoji)出现 Incorrect string value
    根据html页面id寻找对应的Js文件
    Django Pagination
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5595681.html
Copyright © 2011-2022 走看看