acm CodeForces 546B
2015-07-17 09:39
369 查看
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
Input
Output
Input
Output
Sample Output
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.
#include<algorithm>
#include<cstdio>
using namespace std;
int const maxn=3000;
int a[maxn];
int main()
{
int n,sum;
while(scanf("%d",&n)!=EOF)
{
sum=0;
for(int i=0;i<n;i++)
scanf("%d",a+i);
//cin>>a[i];
sort(a,a+n);
for(int i=1;i<n;i++)
{
while(a[i]<=a[i-1])
{
++a[i];
sum++;
}
}
printf("%d\n",sum);
}
return 0;
}
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
Input
4 1 3 1 4
Output
1
Input
5 1 2 3 2 5
Output
2
Sample Output
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.
#include<algorithm>
#include<cstdio>
using namespace std;
int const maxn=3000;
int a[maxn];
int main()
{
int n,sum;
while(scanf("%d",&n)!=EOF)
{
sum=0;
for(int i=0;i<n;i++)
scanf("%d",a+i);
//cin>>a[i];
sort(a,a+n);
for(int i=1;i<n;i++)
{
while(a[i]<=a[i-1])
{
++a[i];
sum++;
}
}
printf("%d\n",sum);
}
return 0;
}
相关文章推荐
- 遍历Map集合
- Windows 8(虚拟机环境)安装.NET Framework3.5(includes .NET 2.0 and 3.0)
- 计算机中浮点数的表示
- Hadoop1.2.1单机版部署
- MySQL打开的文件描述符限制
- js常用插件
- oracle从备份归档日志的方法集中回收
- const修饰符
- 使用java和javascript判断当前浏览者的操作系统
- UVA 11462 Age Sort
- iPhone 6 / 6 Plus 设计·适配方案
- ArcEngle中空值(Null \ Nodata)值的处理
- ACM比赛
- Oracle运维操作集锦[持续更新]
- iOS面试必备看看总有好处
- wget下载FTP目录
- 生成可重集的排列
- Android的Scroller介绍
- editplus打造java运行环境(安装、配置、操作)
- Spring MVC+FreeMarker实现页面按钮权限控制1