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 ...
随机推荐
- commonAncestor
commonAncestor 光标或选区所在区域最外层的祖先节点
- Kattis - sortofsorting 【排序】
题意 给出一系列字符串,然后要排序 排序规则 只按前两位按字典序来排序,如果前两位完全一样,则按输入的顺序来排 思路 要用 冒泡排序 不能用STL里面的 SORT 因为它不稳定 AC代码 #inclu ...
- DevOps能力是落地微服务的前提
在软件开发领域不存在银弹,当用一项新的技术或新的架构时一定要明白其背后的原理,确保把合适的技术应用在合适的项目上,而不是盲目跟风. 单体应用伸缩性差,而且随着应用规模的扩大,业务逻辑和开发部署过程都变 ...
- spring RMI的使用
Spring整合RMI的原理 客户端的核心是RmiProxyFactoryBean,包含serviceURL属性和serviceInterface属性. 通过JRMP访问服务.JRMP JRMP:ja ...
- 【TopCoder】SRM160 DIV1总结
做了两道题之后才发现做的是DIV1,不是DIV2,DIV1的第二道题是DIV1的第三道题,果断决定第3题就不看了=.= 250分题:给定一个时间起点8:00 AM DAY 1,再给出一组时间终点,格式 ...
- jsonp跨域总结
同源限制: 浏览器不允许一个域的脚本请求另一个域的文档,通俗来说,不允许访问不同协议.不同域名或不同端口的文档 跨域处理方法: 1.jsonp 前提: 浏览器虽然对ajax请求做出了限制,但scrip ...
- INSPIRED启示录 读书笔记 - 第7章 管理产品经理
产品总监的关键职责 1.组建优秀的产品经理团队 如果产品经理不称职,只能退而求其次,请其他团队成员(比如主程序员)越俎代庖 新产品经理必须经过约三个月刻苦学习才能开始管理产品,管理者应该为新人创造学习 ...
- MapReduce-从HBase读取数据处理后再写入HBase
MapReduce-从HBase读取处理后再写入HBase 代码如下 package com.hbase.mapreduce; import java.io.IOException; import o ...
- jsp连接sqlServer数据库教程、jsp连接sqlServer数据库报ClassNotFoundException异常
jsp连接sqlServer数据库教程: 首先讲下我用的工具版本以供参考: jar包:jtds1.3.1.jar 下载地址:点击进入 数据库:SQL Server2012 服务器:Tomcat8.0 ...
- 页面js框架
js 模板,所有页面控制js,以闭包形式编写代码,降低浏览器内存消耗,加快运行速度 请按照此结构编写,便于后期前端维护和修改1. [代码][JavaScript]代码 /** * js 模板,所有 ...