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[];
//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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int a[maxn];
int b[maxn];
int main()
{
int n=read();
for(int i=;i<n;i++)
{
a[i]=read();
b[a[i]]++;
}
sort(a,a+n);
int ans=;
for(int i=;i<maxn;i++)
{
if(b[i]>)
{
ans+=b[i]-;
b[i+]+=b[i]-;
b[i]=;
}
}
cout<<ans<<endl;
}

Codeforces Round #304 (Div. 2) B. Soldier and Badges 水题的更多相关文章

  1. Codeforces Round #304 (Div. 2) C. Soldier and Cards 水题

    C. Soldier and Cards Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546 ...

  2. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

  3. Codeforces Round #304 (Div. 2) B. Soldier and Badges【思维/给你一个序列,每次操作你可以对一个元素加1,问最少经过多少次操作,才能使所有元素互不相同】

    B. Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #304 (Div. 2) C. Soldier and Cards —— 模拟题,队列

    题目链接:http://codeforces.com/problemset/problem/546/C 题解: 用两个队列模拟过程就可以了. 特殊的地方是:1.如果等大,那么两张牌都丢弃 : 2.如果 ...

  5. DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...

  6. queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

    题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...

  7. 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

    题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...

  8. 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...

  9. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

随机推荐

  1. Mysql储存过程7: case

    #用在储存过程中: create procedure k() begin declare number int; )); case number then select '>0'; else s ...

  2. Python中如何Debug

    debug是编码是非常重要的调试技巧,通过在运行过程中设置断点,帮助开发人员更好的理解运行过程. Python中debug不像JAVA或者C++那样在IDE中设置断点那么直观. Python的debu ...

  3. 发布PHP项目(nginx+PHP7+mysql 5.6)

    一.环境检查 1.检查nginx ps -ef | grep "nginx" 显示如下内容则代表nginx启动正常 root 3285 1 0 12:57 ? 00:00:00 n ...

  4. (四)Spring 对DAO 的支持

    第一节:Spring 对JDBC 的支持 1,配置数据源dbcp: 2,使用JdbcTemplate: 3,JdbcDaoSupport 的使用: 4,NamedParameterJdbcTempla ...

  5. MySQL之基础功能

    一.视图 视图:是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据 视图有如下特点: 1. 视图的列可以来自不同的表,是表的抽象和逻辑意义上建立的新关系. 2. 视图是 ...

  6. java中Property类的基本用法

    1 配置.properties文件 2 获取输入流的方法 1)FileInputStream fi = new FileInputStream(properties文件路径); 2)InputStre ...

  7. apache kafka系列之jmx监控指标参数

    https://blog.csdn.net/lizhitao/article/details/35986849

  8. sql server 存储过程解密

    Create PROCEDURE [dbo].[sp_windbi$decrypt] () AS /**//* 王成辉翻译整理,转贴请注明出自微软BI开拓者www.windbi.com 调用形式为: ...

  9. new Date()时间

    var myDate = new Date(); myDate.toLocaleDateString():可以获取当前日期myDate.toLocaleTimeString(); 可以获取当前时间 扩 ...

  10. Java Programs

    Java Programs Fibonacci series in Java public class FibonacciExample { public static void main(Strin ...