「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\)的链有多少条(注意每个点 ...
随机推荐
- iptables 删除规则
iptables -nL --line-number显示每条规则链的编号 iptables -D FORWARD 2删除FORWARD链的第2条规则,编号由上一条得知.如果删除的是nat表中的链,记得 ...
- JQuery---高级选择器
一.派生选择器 例如:$('#bavBar a') 二.孩子选择器 例如:$('body > p') 三.相邻兄弟选择器 例如:$('h2 + div') 四.属性选择器 1.$('img[a ...
- element表格多选实现单选
9.element多选表格实现单选 userChoose(selection, row) { console.log(selection,'selection') console.log(row,'r ...
- oracle使用TKPROF 工具来查询SQL性能状态
SQL trace 工具收集正在执行的SQL的性能状态数据并记录到一个跟踪文件中. 这个跟踪文件提供了许多有用的信息,例如解析次数.执行次数,CPU使用时间等.这些数据将可以用来优化你的系统. 设置S ...
- nio FileChannel中文乱码问题
最近用nio读取文件时,英文正常,读取中文时会出现乱码,经查可以用Charset类来解决: 代码如下: package com.example.demo; import java.io.FileNot ...
- H3C 传输层
- 【CSS3】使用CSS3制作全屏切换效果
在线演示: DEMO DEMO中及以下代码并没有写兼容代码,请使用高级浏览器打开,IE版本对CSS3支持并不太友好,IE11打开没有滚屏效果. 兼容代码前缀: -webkit- -moz- -o- - ...
- Windows 10 Shared folder - 5168: Spn check for SMB/SMB2 fails.
在搭建 Win10 Shared Folder 时,运行一段时间后就报 Access denied. 导致 Shared Folder 访问不了. 查了下 Event Viewer -> Win ...
- Python--day38---进程间通信--初识队列(multiprocess.Queue)
初识队列: 进程间通信IPC(Inter-Process Communication) 1,队列的方法: q = Queue(5)1,q.put(1) #把1放进队列 2,print(q.full() ...
- H3C RIP基本配置