Soldier and Badges (set的检索简单运用)
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的检索简单运用)的更多相关文章
- CF Soldier and Badges (贪心)
Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- 「CodeForces 546B」Soldier and Badges 解题报告
CF546B Soldier and Badges 题意翻译 给 n 个数,每次操作可以将一个数 +1,要使这 n 个数都不相同, 求最少要加多少? \(1 \le n \le 3000\) 感谢@凉 ...
- 题解 CF546B Soldier and Badges
CF546B Soldier and Badges 简单的贪心qwq 排个序,如果当前数与之前的数相重,已经用过,则加到一个之前没有用过的数 #include<cstdio> #inclu ...
- 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 ...
- 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
- CF 546 B Soldier and Badges(贪心)
原题链接:http://codeforces.com/problemset/problem/546/B 原题描述: Soldier and Badges Colonel has n badges. H ...
- 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 ...
- B - Soldier and Badges
Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Colone ...
- 【codeforces 546B】Soldier and Badges
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- iOS NSSet 学习 “无序数组” & 去重 案例
“NSSet,NSMutableSet,和NSCountedSet类声明编程接口对象的无序集合(散列存储:在内存中的存储位置不连续). 而NSArray,NSDictionary类声明编程接口对象的有 ...
- C# XMLHttpRequest对象—Ajax实例
Get: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ...
- Matlab命令合集 妈妈再也不用担心我不会用matlab了
matlab命令 一.常用对象操作:除了一般windows窗口的常用功能键外.1.!dir 可以查看当前工作目录的文件. !dir& 可以在dos状态下查看.2.who 可以查看当前工作空间变 ...
- 转:APDU命令格式
CLA INS P1 P2 Lc Data Le 其中CLA为指令类别:INS为指令码:P1.P2为参数:Lc为Data的长度:Le为希望响应时回答的数据字节数,0表最大可能长度. 一 ...
- flex 实现图片播放 方案二 把临时3张图片预加载放入内存
该方案,是预加载:前一张,当前,下一张图片,一共3张图片放入内存中.这样对内存的消耗可以非常小,加载之后的图片就释放内存. 下面示例一个是类ImagePlayers,一个是index.mxml pac ...
- 关于Class.getResourceAsStream
Properties properties = new Properties(); properties.load(new InputStreamReader(CharactorTest.cl ...
- point-to-point(点对点) 网口
点对点连接是两个系统或进程之间的专用通信链路.想象一下直接连接两个系统的一条线路.两个系统独占此线路进行通信.点对点通信的对立面是广播,在广播通信中,一个系统可以向多个系统传输. 点对点通信在OSI协 ...
- Nagios 工作原理
Nagios 工作原理 nagios通过nrpe插件和snmp协议进行主动监控.至于什么是主动监控可以参考上面所述.简单理解决就是nagios按照检测周期主动的获取远程主机的数据.这样一来实时性就要差 ...
- springmvc请求参数的绑定和获取
请求参数的绑定和获取: 获取页面请求的参数,是javaweb必不可少的一个环节,在struts中,是通过再Action中定义属性,或者Model的方式进行数据绑定和获取.需要提供setter或gett ...
- space sniffer清理的空间
部分超级大的单文件,比如数据库 C:\inetpub\logs\LogFiles\W3SVC4 C:\Users\clu\AppData\Local\JetBrains\Transient C:\Us ...