码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 546B

时间:2016-07-23 14:59:29      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

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

题意就是把所有的都弄成不一样的数,最少一共需要加几,思路就是前面一个和后面一个相同的话,后面一个就加1,贪心思想啦


#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <string>
using namespace std;
#define Maxn

int A[10000];
int main()
{
	int T;
	int count = 0;
	cin >> T;
	for(int i = 0; i < T; i++)
	{
		scanf("%d",&A[i]);
	}
	sort(A,A+T);
	for(int i = 0; i < T-1; i++)
	{
		if (A[i] == A[i+1])
		{
			// count++;
			for(int j = i+1; j < T; j++)
			{
				if (A[j] == A[i])
				{
					A[j] += 1;
					count++;
				}
			}

		}
	}
	std::cout << count;
}

  

codeforces 546B

标签:

原文地址:http://www.cnblogs.com/yakoazz/p/5698694.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!