「CodeForces 546B」Soldier and Badges 解题报告
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 解题报告的更多相关文章
- 「日常训练」Soldier and Badges (CFR304D2B)
题意 (Codeforces 546B) 问对一个序列最少需要增减几个1能使其彼此不同. 分析 模拟处理.需要注意的是,尽管题目中说了an<=3000,问题是,如果一群a全是3000呢(滑稽), ...
- 「CTS2019 | CTSC2019」氪金手游 解题报告
「CTS2019 | CTSC2019」氪金手游 降 智 好 题 ... 考场上签到失败了,没想容斥就只打了20分暴力... 考虑一个事情,你抽中一个度为0的点,相当于把这个点删掉了(当然你也只能抽中 ...
- 【codeforces 546B】Soldier and Badges
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 「Luogu P2015」二叉苹果树 解题报告
题面 一个二叉树,边数为n\((2<n\le 100)\),每条边有一个权值,求剪枝后剩下p\((1<p<n)\)条边,使p条边的权值和最大 还看不懂?-- 2 5 input:5 ...
- 「Luogu P3866」[TJOI2009]战争游戏 解题报告
题面 好难表述啊~ 在n*m的矩阵上,有一些大兵(为0),一些空地(一个正整数),障碍物(-1),现在摧毁一些空地,使所有大兵不能走出矩阵去(代价为表示空地的整数),求最小代价 思路: 网络流最小割 ...
- 「Luogu P1210」回文检测 解题报告
题面 这是一道诡异的黄题 居然让你求一串吧啦吧啦的东西中 字母(大小写)最长的回文串的长度,还要输出完整的串 吐血 思路: 保持淡定,我们啥都不会,就会Manacher,那就用Manacher大法! ...
- 「Luogu P4987」回文项链 解题报告
题面 求环中的长度为k(k为奇数)且回文中心不同的回文串个数 思路: 刚学manacher算法,就送上一道模板题,此题注重对manacher算法的理解 Manacher,但是不用插入其他符号,因为k是 ...
- 「Luogu P1435」回文字串 解题报告
题面 主要大衣大意: 给定一个字符串,求至少加入多少个字符才能使字符串变成回文字符串 下面就是我一本正经的胡说八道题解 思路: 很显然,这应该是一道典型的最长公共子序列的题目 因此,主要思想就是DP ...
- 洛谷 P4714 「数学」约数个数和 解题报告
P4714 「数学」约数个数和 题意(假):每个数向自己的约数连边,给出\(n,k(\le 10^{18})\),询问\(n\)的约数形成的图中以\(n\)为起点长为\(k\)的链有多少条(注意每个点 ...
随机推荐
- 【阿里云新品发布·周刊】第13期:链路追踪 Tracing Analysis 商业化首发
点击订阅新品发布会! 新产品.新版本.新技术.新功能.价格调整,评论在下方,下期更新!关注更多内容,了解更多 最新发布 链路追踪 Tracing Analysis 商业化首发 2019年6月12日15 ...
- top 9 Cloud Computing Failures
top 9 Cloud Computing Failures Outages, hacks, bad weather, human error and other factors have led t ...
- iptables 过滤条件(Matches)
iptables可让你设置多种过滤条件,但是某些条件需要核心有提供相关功能才行.Iptables本身內建一般性的Internet Protocol (IP) 过滤条件,也就是說,即时沒载入任何扩充模组 ...
- Android Studio(一):介绍、安装、配置
Android Studio相关博客: Android Studio(一):介绍.安装.配置 Android Studio(二):快捷键设置.插件安装 Android Studio(三):设置Andr ...
- Git Commit Message 规范
今天来说说团队开发中,对于 Git commit message 规范问题. 社区上有各种 Commit message 的规范,本文介绍 Angular 规范,目前使用较广,比较合理和系统化,并且有 ...
- 深入Java线程管理(五):线程池
这几天主要是狂看源程序,在弥补了一些以前知识空白的同时,也学会了不少新的知识(比如 NIO),或者称为新技术吧. 线程池就是其中之一,一提到线程,我们会想到以前<操作系统>的生产者与消费者 ...
- git 删除时报 the branch is not fully merged 这是什么意思
今天删除本地分支 git branch -d XX 提示: the branch XXX is not fully merged原因:XXX分支有没有合并到当前分支的内容 解决方法:使用大写的D 强制 ...
- hibernate无限递归问题
项目异常如下: 2018-01-26 17:12:38.162 WARN 3128 --- [nio-8080-exec-6] .w.s.m.s.DefaultHandlerExceptionReso ...
- js 制作分页
如图所示 在html中调用方法 getpage(7, 1, 1, 'URL') 1.page.js文件 代码 function getpage(count, countPage, pageIndex, ...
- springboot + rabbitmq发送邮件(保证消息100%投递成功并被消费)
前言: RabbitMQ相关知识请参考: https://www.jianshu.com/p/cc3d2017e7b3 Linux安装RabbitMQ请参考: https://www.jianshu. ...