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. SSH基本原理

    SSH原理与运用:远程登录 作者: 阮一峰 年12月21日 SSH是每一台Linux电脑的标准配置. 随着Linux设备从电脑逐渐扩展到手机.外设和家用电器,SSH的使用范围也越来越广.不仅程序员离不 ...

  2. maxCompute odps 行转列

    select name ,REGEXP_REPLACE(str,"[\\[\"\\]]",'') from ( select trans_array(, ",& ...

  3. JVM -XX: 参数列表

    功能开关: 参数 默认值或限制 说明 参数 默认值 功能 -XX:-AllowUserSignalHandlers 限于Linux和Solaris,默认不启用 允许为java进程安装信号处理器,信号处 ...

  4. 解决ubuntu的Idea启动No JDK found. Please validate either IDEA_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation.

    直接在idea安装目录下运行idea.sh可以正常启动,但是使用ubuntu的dash搜索出来的idea报错,No JDK found. Please validate either IDEA_JDK ...

  5. sleep usleep nanosleep alarm setitimer使用

    sleep使用的是alarm之类的定时器,定时器是使得进程被挂起,使进程处于就绪的状态. signal+alarm定时器 alarm参数的类型为uint, 并且不能填0 #include <st ...

  6. jq实现超级简单的隔行变色

    文章地址:https://www.cnblogs.com/sandraryan/ <!DOCTYPE html> <html lang="en"> < ...

  7. halcon坐标转换(机器人坐标转换用)

    #图像坐标r:=[431, 355, 507, 53, 507]c:=[505, 543, 316, 127, 883]#物理坐标(例如机器人坐标)r1:=[0, 2.0, -2.0, 10, -2. ...

  8. Java集合系统

    前言: 要想学习java的集合体系,就必须先了解java的集合框架,总的来说,分为Collection和Map体系. Collection集合框架: Map集合框架: 一. Collection接口 ...

  9. layer/layui弹出层插件bug

    <button class="layui-btn" lay-submit lay-filter="formDemo" id="layui-btn ...

  10. 关于Android studio Haxm加速器安装

    首先,在SDK manager中要安装如下选项 安装后,在启动虚拟机时如果提示你没有Install Haxm,在目录sdk\extras\intel\Hardware_Accelerated_Exec ...