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 ...
随机推荐
- js判断有无属性
访问元素属性 getAttribute 不存在返回null,特性名可不区分大小写 dom对象访问公共属性,自定义属性不能访问,div.id 访问对象属性 1.使用in关键字 该方法可以判断对象的自有属 ...
- HP小型机维护
(一)文件系统维护 . 监控文件系统的使用 # bdf . 监控文件目录的使用 # du -sk /myfs2/* (二)网络系统维护 1. 相关配置文件 1). 主机名定义文件:/etc/hosts ...
- MongoDB命令语法小用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using MongoDB; ...
- Kubernetes Controller Manager
Controller Manager 作为集群内部的管理控制中心,负责集群内的Node.Pod副本.Service Endpoint.NameSpace.ServiceAccount.Resource ...
- cuffdiff problem--Performed 0 isoform-level transcription difference tests
如何解决cuffdiff运行结果中表达量为0的情况? cuffdiff -o cdiffout -b ref.fasta -u -p 15 --library-type fr-firststrand ...
- PHP开发框架
利用PHP开发框架可以帮助你编写干净和可重用的代码.PHP开发框架遵循MVC设计模式,以确保能够明确区分逻辑和演示文稿.但是有关PHP框架的争论也不少,这是因为有的人喜欢性能,有的人喜欢文档,而有的人 ...
- json数据与Gson工具类的使用
JS中使用JSON JSON对象 --> JSON字符串:JSON.stringify(对象) JSON字符串 --> JSON对象:JSON.parse(JSON字符串) <scr ...
- java中,return和return null有什么区别吗?
java中,return和return null有什么区别吗? 最大的区别:return;方法的返回值必须是void!return null;方法的返回值必须不是 原始数据类型(封装类除过)和void ...
- mysqldump 用法汇总
mysql mysqldump 只导出表结构 不导出数据 复制代码代码如下: mysqldump --opt -d 数据库名 -u root -p > xxx.sql 备份数据库 复制代码代 ...
- java创建多线程的三种方式
/***************************继承Thread类创建多线程************************/ public class FirstThread extends ...