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.

Input

4

1 3 1 4

Output

1

思路:让这些数全都不一样就可以了!!!建立数组循环,从第二个开始,每次检索并增加,知道set堆里面没有相同的位置为止!!!

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{ int n;
cin>>n;
set <int> s;
int a[];
int flag=;
for(int i=;i<n;i++)
cin>>a[i];
s.insert(a[]);
set<int>::iterator it;
for(int i=;i<n;i++)
{
it=s.find(a[i]);
while(it!=s.end())
{
a[i]++;
flag++;
it=s.find(a[i]); }
s.insert(a[i]);
}
cout<<flag<<endl; return ;
}

Soldier and Badges (set的检索简单运用)的更多相关文章

  1. CF Soldier and Badges (贪心)

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

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

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

  3. 题解 CF546B Soldier and Badges

    CF546B Soldier and Badges 简单的贪心qwq 排个序,如果当前数与之前的数相重,已经用过,则加到一个之前没有用过的数 #include<cstdio> #inclu ...

  4. 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 ...

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

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

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

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

  7. 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 ...

  8. B - Soldier and Badges

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

  9. 【codeforces 546B】Soldier and Badges

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

随机推荐

  1. 转:MFC中屏蔽ESC和回车关闭对话框

    解决方法是在 CDialog::PreTranslateMessage() 的重载函数中将ESC和回车按键的消息处理掉. 直接上代码: CResultCollectorDlg::PreTranslat ...

  2. 014_HDFS存储架构、架构可靠性分析、副本放置策略、各组件之间的关系

    1.HDFS存储架构

  3. Java中ArrayList和LinkedList区别、ArrayList和Vector的区别

    一般大家都知道ArrayList和LinkedList的大致区别: 1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机访问get和set,Ar ...

  4. 20145240 《Java程序设计》第五周学习总结

    20145240 <Java程序设计>第五周学习总结 教材学习内容总结 语法与继承结构 8.1.1使用try.catch java中所有的错误都会被打包为对象,并提供了特有的语句进行处理. ...

  5. string 类(二)

    处理string对象中的字符: 在cctype头文件中定义了一组标准库函数来处理string对象中的字符,比如检查一个string对象是否包含空白,或者把string对象中的字母改成小写,再或者查看某 ...

  6. POJ2741 Colored Cubes

    Description There are several colored cubes. All of them are of the same size but they may be colore ...

  7. 页面js框架

    js 模板,所有页面控制js,以闭包形式编写代码,降低浏览器内存消耗,加快运行速度  请按照此结构编写,便于后期前端维护和修改​1. [代码][JavaScript]代码 /** * js 模板,所有 ...

  8. (四) tensorflow笔记:常用函数说明

    tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 ...

  9. Struts2学习(1)

    struts2概述 1.struts2框架应用javaee三层结构中web层框架. 2.strut2框架在struts1和webwork基础之上发展全新的框架. 3.struts2解决的问题: 4.版 ...

  10. python3 列表属性

    1.合并 >>> l1=[1,2,3,'e']>>> l2=['f',34,'feel']>>> l1+l2[1, 2, 3, 'e', 'f', ...