CF546B Soldier and Badges

简单的贪心qwq

排个序,如果当前数与之前的数相重,已经用过,则加到一个之前没有用过的数

#include<cstdio>
#include<algorithm>
using namespace std;
int n,ans,a[3005];
int main() {
scanf("%d",&n);
for (int i=0; i<n; i++) scanf("%d",&a[i]);
sort(a,a+n);
for (int i=1,last=a[0]; i<n; i++)
if (a[i]>last) last=a[i];
else ans+=last-a[i]+1,last++;
printf("%d",ans);
}

题解 CF546B Soldier and Badges的更多相关文章

  1. 「CodeForces 546B」Soldier and Badges 解题报告

    CF546B Soldier and Badges 题意翻译 给 n 个数,每次操作可以将一个数 +1,要使这 n 个数都不相同, 求最少要加多少? \(1 \le n \le 3000\) 感谢@凉 ...

  2. Codeforces Round #304 (Div. 2) B. Soldier and Badges 水题

    B. Soldier and Badges Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/54 ...

  3. CF Soldier and Badges (贪心)

    Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

  5. CF 546 B Soldier and Badges(贪心)

    原题链接:http://codeforces.com/problemset/problem/546/B 原题描述: Soldier and Badges Colonel has n badges. H ...

  6. Codeforces Round #304 (Div. 2) B. Soldier and Badges【思维/给你一个序列,每次操作你可以对一个元素加1,问最少经过多少次操作,才能使所有元素互不相同】

    B. Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standa ...

  7. 【codeforces 546B】Soldier and Badges

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

  8. Soldier and Badges (set的检索简单运用)

    Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolne ...

  9. B - Soldier and Badges

    Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Colone ...

随机推荐

  1. [SUCTF 2019]EasySQL(堆叠注入配合sql_mode)

    考点:1.堆叠注入 2.set sql_mode=PIPES_AS_CONCAT;将||视为字符串的连接操作符而非或运算符 意外:注入* 复现: 1;set sql_mode=PIPES_AS_CON ...

  2. AcWing 1010. 拦截导弹

    //贪心加dp #include<iostream> using namespace std ; ; int n; int q[N]; int f[N]; int g[N];//存每个序列 ...

  3. Visual detection of structural changes in time-varying graphs using persistent homology

    PKU blog about this paper Basic knowledge:  1. what is time-varying graphs? time-varying graph VS st ...

  4. 用html5自带表单验证 并且用ajax提交的解决方法(附例子)

    用submit来提交表单,然后在js中监听submit方法,用ajax提交表单最后阻止submit的自动提交. 在标准浏览器中,阻止浏览器默认行为使用event.preventDefault(),而在 ...

  5. (转)Hadoop 简介

    转自:http://www.open-open.com/lib/view/open1385685943484.html mapreduce是一种模式,一种什么模式呢?一种云计算的核心计算模式,一种分布 ...

  6. 基于PO和单例设计模式用python+selenium进行ui自动化框架设计

    一)框架目录的结构 二)config包当中的config.ini文件主要是用来存项目的绝对路径,是为了后续跑用例和生成测试报告做准备然后目前的配置文件大都会用yaml,ini,excel,还有.py也 ...

  7. Activiti+Shiro实战

    有人曾说:人的差距都在业余时间拉开的……嗯,我现在深刻理解着这句话,作为一个程序员,技术男,就得不断学习新的技术,跟上时代步伐,才会让自己更有价值~~~~以下这个项目是个人利用业余时间学习并实践的~如 ...

  8. MySQL排序查询

    语法:① SELECT 查询 (要找的东西)②FROM 表 (在哪个表找)③[WHERE 筛选条件](取出重要的或有用的)④ORDER BY 排序列表 [ASC|DESC] (排序的关键字 字段)([ ...

  9. CAN报文格式

    CAN协议的报文传输过程中有:数据帧.远程帧.错误帧.过载帧和帧间隔. 1.数据帧:用于发送节点向接收节点传送数据的帧. 2.远程帧:用于接收节点向具有相同ID的发送节点传送数据的帧. 3.错误帧:用 ...

  10. layui之普通数据表格显示switch选择表单组件

    先看效果: 一般这写什么switch组件,下拉框组件只在表单显示,如果要在其他地方显示就要注意一下细节 默默跳槽一下这个layui,真的蛋疼,每次用它东西都要各种设置东西,无语 接下来看下代码: HT ...