CF 546 B Soldier and Badges(贪心)
原题链接:http://codeforces.com/problemset/problem/546/B
原题描述:
Soldier and Badges
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
First line of input consists of one integer n (1 ≤ n ≤ 3000).
Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.
Output
Output single integer — minimum amount of coins the colonel has to pay.
Example
4
1 3 1 4
1
5
1 2 3 2 5
2
题目感觉很水啊,数量最多才3000个,就算3000个每个都是3000增加后的最大值也不会超过6000,所以我开了个10005的数组;先将每个读入,然后统计1-10000之间每个数字的个数,比如说3000这个数字有2个那么b[3000]值为3,然后让b[3001]增加2,b[3000]变为1,同时需要增加的总量增加2以此类推统计增加的总量即可,也不知道别人看不看得懂。。。。看看代码应该能理解
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL; int a[],b[]; int main()
{
int n,sum=;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
b[a[i]]++;
}
for(int i=;i<=;i++)
{
if(b[i]>)b[i+]+=b[i]-,sum+=b[i]-,b[i]=;
}
cout<<sum<<endl;
return ;
}
CF 546 B Soldier and Badges(贪心)的更多相关文章
- CF Soldier and Badges (贪心)
Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
- 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 ...
- 题解 CF546B Soldier and Badges
CF546B Soldier and Badges 简单的贪心qwq 排个序,如果当前数与之前的数相重,已经用过,则加到一个之前没有用过的数 #include<cstdio> #inclu ...
- 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 ...
- 「CodeForces 546B」Soldier and Badges 解题报告
CF546B Soldier and Badges 题意翻译 给 n 个数,每次操作可以将一个数 +1,要使这 n 个数都不相同, 求最少要加多少? \(1 \le n \le 3000\) 感谢@凉 ...
- 【codeforces 546B】Soldier and Badges
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 546 D. Soldier and Number Game(素数有关)
Description Two soldiers are playing a game. At the beginning first of them chooses a positive integ ...
- Soldier and Badges (set的检索简单运用)
Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolne ...
随机推荐
- jenkins初级使用篇
1.jenkins的初级使用 1.1 介绍 创建一个项目 可以看到当前登陆用户及用户权限 可以查看到所有构建过的项目的历史 系统管理 My Views:视图功能,我们可以自己创建一个自己的视图 系统管 ...
- CentOS7linux通过http配置共享自动创建yum源的shell脚本
因工作需要用到,所以记录一下配置流程 环境介绍: 两台CentOS7系统 yum源服务主节点IP:192.168.1.78 从节点IP:192.168.1.79(79从78上获取yum源) 配置78节 ...
- [Git] 018 冲突在所难免,需要巧妙化解
0. 回顾 [Git] 005 初识 Git 与 GitHub 之分支 中"4.2 情形二"的 9 提及了"解决冲突" 当时没有展开,这回详谈 我这回反其道而行 ...
- codeforces 597 div 2
A 题意: 有无限个方块,上面分别是0,1,2......若方块i可以被表示为ax+by(x,y>0),则方块为白色,否则为黑色,给出a,b.问黑方块是否有无限个. 分析: 1:若(a,b)=1 ...
- 吴恩达深度学习:2.1Logistic Regression逻辑回归及其损失函数
1.Logistic Regression是一个二元分类问题 (1)已知输入的特征向量x可能是一张图,你希望把它识别出来,这是不是猫图,你需要一个算法,可以给出预测值,更正式的y是一个概率,当输入特征 ...
- Excel批量插入的SQL Server
首先新建一个WPF的项目,名为ExcelToServerDemo 到Nuget去安装NPOI的Nuget包,点击安装即可,会自动引用项目. 新建一个Student的表格,有名字,年龄,性别,地址,以及 ...
- vue data数据变化 页面数据不更新问题
问题: <template> <div class="container"> <div v-for="(item, index) in ar ...
- socket 服务器向指定的客户端发消息
一.需求 需求如题. 当多个客户端连接服务器时,服务器如何给指定的客户端发送消息. 二.解决方案 核心思想: 在服务器端,需保存不同客户端的socket列表及客户端相关信息. socket含有发送方和 ...
- 基于numpy的绘图
import numpy as np #import matplotlib.pyplot as plt dataset = np.loadtxt('1.csv', delimiter=",& ...
- CF 937
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...