zoukankan      html  css  js  c++  java
  • Codeforces Round #304 (Div. 2) B. Soldier and Badges 水题

    B. Soldier and Badges

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/546/problem/B

    Description

    Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.

    For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors.

    Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

    Input

    First line of input consists of one integer n (1 ≤ n ≤ 3000).

    Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.

     

    Output

    Output single integer — minimum amount of coins the colonel has to pay.

    Sample Input

    4
    1 3 1 4

    Sample Output

    1

    HINT

    题意

    可以花1块钱让一个勋章加1点,然后问你要花多少钱才能使所有勋章都不一样

    题解:

    啊,暴力暴力

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    int a[maxn];
    int b[maxn];
    int main()
    {
        int n=read();
        for(int i=0;i<n;i++)
        {   
            a[i]=read();
            b[a[i]]++;
        }
        sort(a,a+n);
        int ans=0;
        for(int i=0;i<maxn;i++)
        {
            if(b[i]>1)
            {
                ans+=b[i]-1;
                b[i+1]+=b[i]-1;
                b[i]=1;
            }
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    python类变量与成员变量,及模块中类变量共享
    python制作GUI界面---搞定软件界面编程
    pycharm运行PyQt5出现错误This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
    pycharm安装包下载慢的问题解决
    DNS隧道实验
    关于虚拟机win Server 2003只能打开百度网页其他网页都打不开??
    Python如何将决策树dot文件转化为png文件
    如何将虚拟机win7成功联网
    关于虚拟机win2003忘记登录密码(待解决)
    虚拟机kali忘记密码后问题解决&&kali用桥接模式成功联网
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4523621.html
Copyright © 2011-2022 走看看