CF546B Soldier and Badges

题意翻译

给 n 个数,每次操作可以将一个数 +1,要使这 n 个数都不相同, 求最少要加多少? \(1 \le n \le 3000\)

感谢@凉凉 提供的翻译

题目描述

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.

输入格式:

First line of input consists of one integer \(n\) ( \(1 \le n \le 3000,1 \le n \le 3000\) ).

Next line consists of \(n\) integers \(a_{i}\) ( \(1 \le a_{i} \le n\) ), which stand for coolness factor of each badge.

输出格式:

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

输入输出样例

输入样例#1:

4
1 3 1 4

输出样例#1:

1

输入样例#2:

5
1 2 3 2 5

输出样例#2:

2

说明

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\) .


思路

其实这道题的思想很简单,就是每次遇到一个没有出现过的的数,就把之前的一个重复的数变成这个数。。。

我的代码可能有点奇怪。。。

我的主要思想是把取到的数的和 - 原来的和,然后就是答案。

具体看代码吧——

代码

#include<cstdio>
#include<queue>
using namespace std;
#define MAXN 3005 int n, ans, t, s;
int nn;
int a[MAXN * 2]; int main(){
scanf( "%d", &n );
for ( int i = 1; i <= n; ++i ) scanf( "%d", &t ), a[t]++, s += t, nn = max( nn, t );//哈希计数
t = 0;
for ( int i = 1; i <= 6000; ++i ){
if ( t == 0 && i > nn ) break;
if ( t > 0 && a[i] == 0 ) t--, ans += i;//把一个该改的数改成这个数
if ( a[i] > 1 ) t += a[i] - 1;//又多了这么多个待改变的数
if ( a[i] ) ans += i;//不改变的话也要加哦
}
printf( "%d\n", ans - s );
return 0;
}

「CodeForces 546B」Soldier and Badges 解题报告的更多相关文章

  1. 「日常训练」Soldier and Badges (CFR304D2B)

    题意 (Codeforces 546B) 问对一个序列最少需要增减几个1能使其彼此不同. 分析 模拟处理.需要注意的是,尽管题目中说了an<=3000,问题是,如果一群a全是3000呢(滑稽), ...

  2. 「CTS2019 | CTSC2019」氪金手游 解题报告

    「CTS2019 | CTSC2019」氪金手游 降 智 好 题 ... 考场上签到失败了,没想容斥就只打了20分暴力... 考虑一个事情,你抽中一个度为0的点,相当于把这个点删掉了(当然你也只能抽中 ...

  3. 【codeforces 546B】Soldier and Badges

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 「Luogu P2015」二叉苹果树 解题报告

    题面 一个二叉树,边数为n\((2<n\le 100)\),每条边有一个权值,求剪枝后剩下p\((1<p<n)\)条边,使p条边的权值和最大 还看不懂?-- 2 5 input:5 ...

  5. 「Luogu P3866」[TJOI2009]战争游戏 解题报告

    题面 好难表述啊~ 在n*m的矩阵上,有一些大兵(为0),一些空地(一个正整数),障碍物(-1),现在摧毁一些空地,使所有大兵不能走出矩阵去(代价为表示空地的整数),求最小代价 思路: 网络流最小割 ...

  6. 「Luogu P1210」回文检测 解题报告

    题面 这是一道诡异的黄题 居然让你求一串吧啦吧啦的东西中 字母(大小写)最长的回文串的长度,还要输出完整的串 吐血 思路: 保持淡定,我们啥都不会,就会Manacher,那就用Manacher大法! ...

  7. 「Luogu P4987」回文项链 解题报告

    题面 求环中的长度为k(k为奇数)且回文中心不同的回文串个数 思路: 刚学manacher算法,就送上一道模板题,此题注重对manacher算法的理解 Manacher,但是不用插入其他符号,因为k是 ...

  8. 「Luogu P1435」回文字串 解题报告

    题面 主要大衣大意: 给定一个字符串,求至少加入多少个字符才能使字符串变成回文字符串 下面就是我一本正经的胡说八道题解 思路: 很显然,这应该是一道典型的最长公共子序列的题目 因此,主要思想就是DP ...

  9. 洛谷 P4714 「数学」约数个数和 解题报告

    P4714 「数学」约数个数和 题意(假):每个数向自己的约数连边,给出\(n,k(\le 10^{18})\),询问\(n\)的约数形成的图中以\(n\)为起点长为\(k\)的链有多少条(注意每个点 ...

随机推荐

  1. mysql数据库之存储引擎

    mysql存储引擎概述 什么是存储引擎?                                                               MYSQL中的数据用各不相同的技术 ...

  2. mysql数据库之mysql下载与设置

    下载和安装mysql数据库 mysql为我们提供了开源的安装在各个操作系统上的安装包,包括ios,liunx,windows. mysql的安装,启动和基础配置-------linux版本 mysql ...

  3. SaltStack之用户账户管理

    在Salt.state中,user 模块是用来创建用户和管理用户设定的,用户可以被设置成 present 状态或者 absent 状态 注释: present:添加用户 absent   : 删除用户 ...

  4. TAE words all

    // vol 1   could do with sth   rhinoplasty   angst   the wee small hours   familial   Munich   gladi ...

  5. JavaScript中判断整数的方法

    一.使用取余运算符判断 任何整数都会被1整除,即余数是0.利用这个规则来判断是否是整数. 1 2 3 4 5 function isInteger(obj) {     return obj%1 == ...

  6. JPA 一对多、多对一注解

    1. @OneToMany @OneToMany 是属性或方法级别的注解,用于定义源实体与目标实体是一对多的关系. 参数 类型 描述 targetEntity Class 源实体关联的目标实体类型,默 ...

  7. 2018-8-10-WPF-可获得焦点属性

    title author date CreateTime categories WPF 可获得焦点属性 lindexi 2018-08-10 19:16:53 +0800 2018-05-15 15: ...

  8. BoundsChecker下载

    首先,单独的BoundsChecker已经没了,被收购了,整合进了DevPartner 其次,DevPartner是收费软件,属于Borland的.官方地址:http://www.borland.co ...

  9. 关于Ping和Tracert命令原理详解

    本文只是总结了两个常用的网络命令的实现原理和一点使用经验说明.这些东西通常都分布在各种书籍或者文章中的,我勤快那么一点点,总结一下,再加上我的一点理解和使用经验,方便大家了解.这些也是很基础的东西,没 ...

  10. 安装node-sass时出现的错误解决方案(Mac自用,也可以借鉴)

    安装node-sass时出现一下错误: gyp ERR! configure error gyp ERR! stack Error: EACCES: permission denied, mkdir ...