codeforces 546B
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
41 3 1 4
1
51 2 3 2 5
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的更多相关文章
- 【codeforces 546B】Soldier and Badges
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 546B C(Contest #1)
Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge ...
- 第一次比赛的 C题 (好后面才补的....) CodeForces 546B
Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge ...
- 「CodeForces 546B」Soldier and Badges 解题报告
CF546B Soldier and Badges 题意翻译 给 n 个数,每次操作可以将一个数 +1,要使这 n 个数都不相同, 求最少要加多少? \(1 \le n \le 3000\) 感谢@凉 ...
- 「日常训练」Soldier and Badges (CFR304D2B)
题意 (Codeforces 546B) 问对一个序列最少需要增减几个1能使其彼此不同. 分析 模拟处理.需要注意的是,尽管题目中说了an<=3000,问题是,如果一群a全是3000呢(滑稽), ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
随机推荐
- 简明Vim练级攻略
原文:酷壳网 vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的.下面的文章翻译自<Learn Vim P ...
- 关于javascript输出中文乱码的问题
今天找到一个引导效果.原来是用英文进行引导.但是我改了里面的英文为汉字就出现乱码的情况.英文提示是在js页面里面完成的.所以最后的解决办法 就是把js文件用记事本打开,然后把文件另存为utf-8的格式 ...
- javascript为目标位置div等设置高度
应该是DOM的东西: document.getElementById("目标id").style.height = 多高(数值)+"px";
- 理解CSS Clip属性及用法
应用Clip属性实现的一个简单效果图: 样式写法: .my-element { position: absolute; clip: rect(10px 350px 170px 0); /* IE ...
- Webservices-2.C#创建web服务,及引用访问、代码访问
注:web服务简介Webservices-1.web服务定义简介 以下均以C#语言为例 一.创建web服务(简单介绍,主要讨论客户端引用) 打开VS创建网站项目,在网站项目中添加“WEB服务(ASMX ...
- 如何编写一个简单的makefile
一个规则的构成 目标:依赖1,依赖2······ 命令 例子: objs := init.o nand.o head.o main.o nand.bin : $(objs) arm-linux-ld ...
- TWIG整合
//数字格式化 {{ (p.oldprice * p.count)|number_format(2,'.',',') }}
- 完美世界-2015校园招聘-java服务器工程师-成都站
给定一个整数,将该整数分解成多个2的幂次方相加的形式,每次都取最大的可以分解出来的2的幂次方 比如 65 64 1 1 1 2 2 package wanmanshijie; import java. ...
- core dump
Core Dump?! 整理:Wilbur Lang 何谓 core? 在使用半导体作为内存的材料前,人类是利用线圈当作内存的材料(发明 者为王安),线圈就叫作 core ,用线圈做的内存就叫作 co ...
- BZOJ 1024 生日快乐
Description windy的生日到了,为了庆祝生日,他的朋友们帮他买了一个边长分别为 X 和 Y 的矩形蛋糕.现在包括windy,一共有 N 个人来分这块大蛋糕,要求每个人必须获得相同面积的蛋 ...