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;
    }
  • 相关阅读:
    [转载]ASP.NET中IsPostBack详解
    [转载]论asp.net out、ref、return
    用CSS让字体在一行内显示不换行
    改变时间格式的方法
    JS方法的使用
    [转载] iframe嵌入网页的用法
    iphone6 inline-flex兼容问题
    ActionResult的其它返回值
    为什么java中只允许继承一个类?
    关于asp.net MVC3 ----@Html.Partial,@Html.Action,@Html.RenderPartial,@Html.RenderAction
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5595681.html
Copyright © 2011-2022 走看看