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. Python 4 函数的参数,内置函数,装饰器,生成器,迭代器,

    一.函数的参数: 1.位置参数:调用函数时根据函数定义的参数位置来传递参数. 2.关键字参数:用于函数调用,通过“键-值”形式加以指定.可以让函数更加清晰.容易使用,同时也清除了参数的顺序需求. 3. ...

  2. 学习小程序第三天 WXML语言特性

    WXML语言特性     1.数据绑定   Musstache 语法 获取json中指定键值:变量名加双括号的绑定语法 如下: (1)绑定文本 注意所有组件和属性 都要小写 (2)绑定属性     ( ...

  3. Linux进程中TIME_OUT解析

    TIMEWAIT状态本身和应用层的客户端或者服务器是没有关系的.仅仅是主动关闭的一方,在使用FIN|ACK|FIN|ACK四分组正常关闭TCP连接的时候会出现这个TIMEWAIT.服务器在处理客户端请 ...

  4. PHP递归和非递归遍历文件夹下文件

    function readDirFiles($dir){ $files= []; $queue=[realpath($dir)]; $currentPath = current($queue); wh ...

  5. C#多线程学习之Thread

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. Ubuntu: 无法使用su命令

    Ubuntu 无法使用su命令解决方案 在Ubuntu上编译Qt环境时发现无法使用su命令切换到root用户,通过网上查找发现解决方案如下: xt@xt-ubuntu:~$ su密码: su:认证失败 ...

  7. Kubernetes RBAC

    在Kubernetes1.6版本中新增角色访问控制机制(Role-Based Access,RBAC)让集群管理员可以针对特定使用者或服务账号的角色,进行更精确的资源访问控制.在RBAC中,权限与角色 ...

  8. idea创建git分支

        此时只是在本地创建好了分支,修改源代码后add,commit将本地分支提交到远程仓库            分支已创建,其它成员此时就可以从git拉分支

  9. 轻量级的Java 开发框架 Spring

    Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Development a ...

  10. 【bzoj4401】块的计数(水dfs)

    题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4401 假设把树划分为x个节点作一块,那么显然只有当x|n的时候才可能存在划分方案,并且这 ...