zoukankan      html  css  js  c++  java
  • Soldier and Badges CodeForces

    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

    Input
    4
    1 3 1 4
    Output
    1
    Input
    5
    1 2 3 2 5
    Output
    2

    Note

    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.

    变不一样  遇到一样的  让指针加一

     1 #include <iostream>
     2 
     3 using namespace std;
     4 #include<stack>
     5 #include<stdio.h>
     6 #include<math.h>
     7 #include<string.h>
     8 #include<map>
     9 #include<queue>
    10 #include<algorithm>
    11 int main()
    12 {
    13     int n,a[6010],i;
    14     while(cin>>n)
    15     {
    16         for(i=0;i<n;i++)
    17             cin>>a[i];
    18         int temp=0;
    19         sort(a,a+n);
    20         int sum=0;
    21         for(i=0;i<n;i++)
    22         {
    23                 if(a[i]>temp)
    24                     {
    25                         temp=a[i];
    26                     }
    27                 else
    28                 {
    29                     sum+=++temp-a[i];
    30                 }
    31         }
    32         cout<<sum<<endl;
    33     }
    34     return 0;
    35 }
    View Code
  • 相关阅读:
    css3
    js的去重
    mongodb的db.collection is not function
    mongoose的关联查询 :populate
    html/css杂题
    经典的Foo和getName
    AngularJS控制器
    AJAX请求小项目
    AngularJS 依赖注入
    Canvas画布实现自定义时钟效果
  • 原文地址:https://www.cnblogs.com/dulute/p/7272554.html
Copyright © 2011-2022 走看看