Codeforces 546b-soldier and Badges

Source: Internet
Author: User

Test instructions
Give some numbers, require that each number is not the same need to add a few


Ideas:
First sort, then increment each, and finally seek the sum of difference

The code is as follows:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <fstream>5#include <cmath>6#include <ctime>7#include <cstdlib>8#include <algorithm>9#include <Set>Ten#include <map> One#include <list> A#include <stack> -#include <queue> -#include <iterator> the#include <vector> -  - using namespacestd; -  + #defineLL Long Long - #defineINF 0x3f3f3f3f + #defineMOD 1000000007 A #defineMAXN 10000010 at #defineMAXM 1000010 -  - Const intMAXM =3005; - intA[MAXM]; -  - //method One: in  - intMain () to { +     intN; -     intsum; the      while(SCANF ("%d", &n) = =1&&N) *     { $Memset (A,0,sizeof(a));Panax Notoginseng         inti; -pos =0; the          for(i =0; I < n; i++ ) +scanf"%d", &a[i]); ASort (A, A +n); the          for(i =1; I < n; i++ ) +         { -              while(A[i] <= a[i-1]) $             { $A[i] + =1; -Sum + =1; -             } the         } -printf"%d\n", sum);Wuyi     } the  -     return 0; Wu } -  About  $  -  - //Method Two: -  A intMain () + { the     intN; -      while(SCANF ("%d", &n) = =1) $     { theMemset (A,0,sizeof(a)); the         intSUM1 =0, sum2 =0; the          for(inti =1; I <= N; i++ ) the         { -scanf"%d", &a[i]); inSum1 + =A[i]; the         } theSort (A +1, a+n+1); Aboutsum2 = a[1]; the          for(inti =2; I <= N; i++ ) the         { the             if(A[i] = = a[i-1]) +a[i]++; -             Else if(A[i] < a[i-1]) theA[i] = a[i-1] +1;BayiSum2 + =A[i]; the         } theprintf"%d\n", Sum2-sum1); -     } -     return 0; the}

Codeforces 546b-soldier and Badges

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.