• 「日常训练」Soldier and Badges (CFR304D2B)


    题意 (Codeforces 546B)

    问对一个序列最少需要增减几个1能使其彼此不同。

    分析

    模拟处理。需要注意的是,尽管题目中说了an<=3000,问题是,如果一群a全是3000呢(滑稽),所以数组要开到6k。
    可以说非常阴险了。

    代码

    #include <bits/stdc++.h>
    #define MP make_pair
    #define PB push_back
    #define fi first
    #define se second
    #define ZERO(x) memset((x), 0, sizeof(x))
    #define ALL(x) (x).begin(),(x).end()
    #define rep(i, a, b) for (int i = (a); i <= (b); ++i)
    #define per(i, a, b) for (int i = (a); i >= (b); --i)
    #define QUICKIO                  
        ios::sync_with_stdio(false); 
        cin.tie(0);                  
        cout.tie(0);
    using namespace std;
    using ll = long long;
    using ull = unsigned long long;
    using pi = pair<int,int>;
    bool ok[6005]; int a[6005]; //WTF!!!!
    int main()
    {
        ll n; ZERO(ok);
        cin>>n; rep(i,1,n) {cin>>a[i];/*ok[a[i]]=true;*/}
        sort(a+1,a+n+1);
        int ans=0;
        rep(i,1,n)
        {
            if(ok[a[i]])
            {
                for(int j=1;;++j)
                {
                    if(!ok[a[i]+j])
                    {
                        //cout<<i<<" "<<a[i]+j<<endl;
                        ok[a[i]+j]=true;
                        ans+=j;
                        break;
                    }
                }
            }
            else ok[a[i]]=true;
        }
        cout<<ans<<endl;
    
        return 0;
    }
    如非注明,原创内容遵循GFDLv1.3发布;其中的代码遵循GPLv3发布。
  • 相关阅读:
    谦卑
    自尊和自我效能
    二手时间读书笔记
    vim学习4
    vim学习3
    hdu 5122 K.Bro Sorting
    hdu 5113 Black And White
    poj 2479 Maximum sum
    poj 2392 Space Elevator
    poj 3666 Making the Grade
  • 原文地址:https://www.cnblogs.com/samhx/p/Codeforces-546B.html
Copyright © 2020-2023  润新知