博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第一次比赛的 C题 (好后面才补的....) CodeForces 546B
阅读量:5025 次
发布时间:2019-06-12

本文共 1896 字,大约阅读时间需要 6 分钟。

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

Input
4 1 3 1 4
Output
1
Input
5 1 2 3 2 5
Output
2

Hint

In first sample test we can increase factor of first badge by 1.

In second sample test we can increase factors of the second and the third badge by 1.

 

 

 

题意:给一串数字,使得他们每个都不一样,需要增加几....

题解;先输入的时候算出和,然后排序,接下来循环,如果后一个等于前一个,a[i]++,如果前一个大于后一个,a[i]加上前一个减去后一个的再加上1,这样,他就不会个前面的相等.....

最后把他们的和算出来,求两个和的差就是答案...

 

 

 

代码如下:

1 #include 
2 #include
3 #include
4 using namespace std; 5 int a[3005]; 6 int main() 7 { 8 int n; 9 while(scanf("%d",&n)==1)10 {11 int sum1=0,sum2=0;12 for(int i=1;i<=n;i++)13 {14 scanf("%d",&a[i]);15 sum1+=a[i];16 }17 sort(a+1,a+n+1);18 sum2=a[1];19 for(int i=2;i<=n;i++)20 {21 if(a[i]==a[i-1])22 a[i]++;23 else if(a[i]

 

 

转载于:https://www.cnblogs.com/huangguodong/p/4746263.html

你可能感兴趣的文章
bug记录_signalr执行$.connnection.testhub结果为空
查看>>
【转】常用的latex宏包
查看>>
[TMS320C674x] 一、GPIO认识
查看>>
酷狗的皮肤文件存放在哪
查看>>
iOS RunLoop简介
查看>>
C++的引用
查看>>
T-SQL查询进阶--深入浅出视图
查看>>
MapKeyboard 键盘按键映射 机械革命S1 Pro-02
查看>>
Android读取url图片保存及文件读取
查看>>
完整ASP.Net Excel导入
查看>>
判断CPU大小端示例代码
查看>>
ARTS打卡第13周
查看>>
循环队列的运用---求K阶斐波那契序列
查看>>
pta 编程题14 Huffman Codes
查看>>
初始化bootstrap treeview树节点
查看>>
python selenium向<sapn>标签中写入内容
查看>>
JS常用坐标
查看>>
使用”结构化的思考方式“来编码和使用”流程化的思考方式“来编码,孰优孰劣?...
查看>>
C#调用斑马打印机打印条码标签(支持COM、LPT、USB、TCP连接方式和ZPL、EPL、CPCL指令)【转】...
查看>>
关于git的认证方式
查看>>