zoukankan      html  css  js  c++  java
  • Codeforces Round #706 (Div. 2) B

    Codeforces Round #706 (Div. 2) B

    大意

    思路

    假设 (b>a) ,那么有 (lceilfrac{a+b}{2} ceil > a)

    所以,如果原数组第一个不存在的数比最大的数更小,那么,执行操作并不会改变 (a,b) 的值。

    反之如果原数组第一个不存在的数比最大的数更大,那么必有 (a=b+1)

    此时每执行一次操作,(a,b) 都会增加1

    代码

    #include <map>
    #include <set>
    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <vector>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    #define ll long long
    #define ull unsigned long long
    #define cint const int&
    #define Pi acos(-1)
    
    const int mod = 1e9+7;
    const int inf_int = 0x7fffffff;
    const ll inf_ll = 0x7fffffffffffffff;
    const double ept = 1e-9;
    
    int t;
    int n, k;
    int a[100100];
    
    int main() {
        cin >> t;
        while(t--) {
            cin >> n >> k;
            for(int i=1; i<=n; i++) cin >> a[i];
            sort(a+1, a+1+n);
            int now = 0, tmp = -1, ans = 1;
            if(k)
            for(int i=1; i<=n; i++) {
                if(a[i] == now) ++now;
                else if(a[i] > now) {
                    a[++n] = (now + a[n]+1)/2;
                    tmp = 0;
                    break;
                }
            }
            sort(a+1, a+1+n);
            for(int i=2; i<=n; i++) {
                if(a[i] != a[i-1]) ++ ans;
            }
            if(tmp) ans += k;
            cout << ans << endl;
        }
        return 0;
    }
    

    26min, -1

  • 相关阅读:
    HDU5772 (最小割)
    HDU 4971 (最小割)
    暑期集训个人赛1
    HDU 5644 (费用流)
    HDU5619 (费用流)
    暑假集训热身赛
    构建之法阅读笔记05
    找小水王
    找水王
    Runner站立会议之个人会议(冲刺二)
  • 原文地址:https://www.cnblogs.com/ullio/p/14515704.html
Copyright © 2011-2022 走看看