第一次比赛的 C题 (好后面才补的....) CodeForces 546B
Description
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.
Sample Input
4
1 3 1 4
1
5
1 2 3 2 5
2
Hint
In first sample test we can increase factor of first badge by 1.
In second sample test we can increase factors of the second and the third badge by 1.
题意:给一串数字,使得他们每个都不一样,需要增加几....
题解;先输入的时候算出和,然后排序,接下来循环,如果后一个等于前一个,a[i]++,如果前一个大于后一个,a[i]加上前一个减去后一个的再加上1,这样,他就不会个前面的相等.....
最后把他们的和算出来,求两个和的差就是答案...
代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int a[];
int main()
{
int n;
while(scanf("%d",&n)==)
{
int sum1=,sum2=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum1+=a[i];
}
sort(a+,a+n+);
sum2=a[];
for(int i=;i<=n;i++)
{
if(a[i]==a[i-])
a[i]++;
else if(a[i]<a[i-])
a[i]+=a[i-]-a[i]+;
sum2+=a[i];
}
printf("%d\n",sum2-sum1);
}
return ;
}
第一次比赛的 C题 (好后面才补的....) CodeForces 546B的更多相关文章
- UVA 10970 第一次比赛 D题 (后面才补的)
Mohammad has recently visited Switzerland. As heloves his friends very much, he decided to buy somec ...
- 小埋的Dancing Line之旅:比赛题解&热身题题解
答疑帖: 赞助团队:UMR IT Team和洛谷大佬栖息地 赛后题解:更新了那两道练手题的题解 赛时公告,不过一些通知也可能在团队宣言里发出 如果各位发现重题,请将你认为重复的题目链接连同这次比赛的题 ...
- 差分模版题(需理解才明白)AT2442 フェーン現象 (Foehn Phenomena)
https://www.luogu.org/problemnew/show/AT2442 #include <bits/stdc++.h> #define read read() #def ...
- sdut oj 1163 C语言实验——排列 (当初不会递归生成排列,这个题目现在才补上 刘汝佳给出了写法 *【模板】 当然有生成全排列的函数存在 )
C语言实验——排列 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 有4个互不相同的数字,请按序输出由其中三个不重复数字组成的排列 ...
- codeforces 1425E,一万种情况的简单题
大家好,欢迎阅读codeforces专题. 我们今天选中的是codeforces 1425场比赛的E题,这是一场印尼多校联合的ICPC的练习赛.ACM赛制,难度也比较近似.我们今天选择的是其中的一道M ...
- 2015 湘潭大学程序设计比赛(Internet)部分题解,其中有一个题与NYOJ1057很像,贪心过~~
仙剑奇侠传 祝玩的开心 ...
- CF-补题1
CF-补题1 1.CodeForces 735C 题意:n个人淘汰赛,两个人可以比赛的条件是:两人打过的场数之差绝对值<2.求冠军最多可以打多少场. 总结:看了题解,转换一下思路.求n个 ...
- 【线性规划与网络流 24题】已完成(3道题因为某些奇怪的原因被抛弃了QAQ)
写在前面:SDOI2016 Round1滚粗后蒟蒻开始做网络流来自我拯救(2016-04-11再过几天就要考先修课,现在做网络流24题貌似没什么用←退役节奏) 做的题目将附上日期,见证我龟速刷题. 1 ...
- 省选训练赛第4场D题(多米诺骨牌)
题目来自FZU2163 多米诺骨牌 Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Vasya很喜欢排多米诺 ...
随机推荐
- 《MFC游戏开发》笔记五 定时器和简单动画
本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9332377 作者:七十一雾央 新浪微博:http:// ...
- hdu 1228 A+B 字符串处理 超级大水题
中文意思不解释. 很水,我本来想用switch处理字符串,然后编译不通过...原来switch只能处理整数型的啊,我都忘了. 然后就有了很挫的一大串if代码了... 代码: #include < ...
- ubtntu怎么安装myeclipse
1.下载jdk.tar.gz文件 2.解压jdk 命令:$sudo tar zxvf ./jdk.tar.gz 3.将解压后的jdk放在/usr/lib/jvm下 4.查看本机是否还有jiava可选 ...
- Android支付宝SDK开发笔记
一.准备工作 〉1.下载开发包 https://b.alipay.com/order/productDetail.htm?productId=2014110308141993&tabId=4# ...
- sql server实用工具sql prompt的安装与注册
说起 sql prompt ,相信一直在sql server 领域摸爬滚打的技术人员们,并不陌生. 它是一款拥有SQL智能提示功能的SQL ServerVS插件.SQL Prompt能根据数据库的对象 ...
- mysql中权限参数说明
1 授权表范围列的大小写敏感性+--------------+-----+-----+---------+----+-----------+------------+| 列 |Ho ...
- Swift 概述及Swift运算符和表达式
Swift 是用于设计 iOS 及 Mac OS X 应用的一门新 语言. Swift 特点 • Swift 保留了 C 与 Objective-C 的优点,并摒弃 其为了兼容 C 语言所 ...
- 生动详细解释javascript的冒泡和捕获,包懂包会(转)
前言:虽然精通jquery,但对它的原型javascript却不是很了解,最近在学习javascript中遇到了一些困难,比如冒泡和捕获,很多次被提到,但又不知究竟应用在何处.找到了一些好文章解惑,在 ...
- 20141009---Visual Studio 2012 预定义数据类型
预定义数据类型 一.值类型 整型:(整数) 有符号整型和无符号整形,区别是有符号的有负数无符号的都是正数, 2x+1 常用int 有符号: 带有正负数,范围为按所写依次增大 ...
- JS学习笔记 -- 定时器,提示框的应用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...