「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\)的链有多少条(注意每个点 ...
随机推荐
- 微博第三方登录时,域名使用错误报错, Laravel \ Socialite \ Two \ InvalidStateException No message
使用微博第三方登录时,报错 Laravel \ Socialite \ Two \ InvalidStateException No message Laravel \Socialite \Two \ ...
- windonws卸载已安装opencv,安装新版本
主要步骤: 步骤一:卸载opencv-python(如果还有安装opencv-contrib-python,也需要卸载) 步骤二:安装新的opencv-python及opencv-contrib-py ...
- 浮动,定位,flex布局
什么是文档流 英文原文是:Normal flow. In CSS 2.1, normal flow includes block formatting of block-level boxes, in ...
- js写出你的名字的拼音,判断哪个字母出现的最多
function fn(str) { var obj = {}; for (var i = 0; i < str.length; i++) { if (!obj[str.charAt(i)]) ...
- Asp.net MVC中如何获取控制器的名称
如果在代码中 当前controller.action的获取RouteData.Route.GetRouteData(this.HttpContext).Values["controller& ...
- 2019-5-27-C#-很少人知道的科技
title author date CreateTime categories C# 很少人知道的科技 lindexi 2019-05-27 19:33:36 +0800 2018-03-16 08: ...
- 2019-8-31-dotnet-core-黑科技·String.IndexOf-性能
title author date CreateTime categories dotnet core 黑科技·String.IndexOf 性能 lindexi 2019-08-31 16:55:5 ...
- linux主编号的动态分配
一些主设备编号是静态分派给最普通的设备的. 一个这些设备的列表在内核源码树的 Documentation/devices.txt 中. 分配给你的新驱动使用一个已经分配的静态编号的机会 很小, 但是, ...
- Character.digit()的意义
最近在阅读Integet.parseInt()源码时,遇到了Character.digit()这个方法,以前没有遇到过,更没使用过,这里查了资料就记录一下. 官方说法是: java.lang.Char ...
- Aizu 0531 "Paint Color" (坐标离散化+DFS or BFS)
传送门 题目描述: 为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌. 三合板上不需要涂色的部分预先贴好了护板. 被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编写一个程序计 ...