Codeforces Round #315 (Div. 2) 569B Inventory

Source: Internet
Author: User

Title: Click Here

Test instructions: give you n, then n number, n number may repeat, may not be 1 to n in the number. Then you use the fewest number of changes, let the sequence contain 1 to n all numbers, and output the final sequence.

Analysis: Greed.

1#include <bits/stdc++.h>2 using namespacestd;3 Const intM = 1e5+5;4 5 intN;6 intA[M];//given sequence7 intMARK[M];//Mark[i] Indicates the number of occurrences of I in a given sequence8 intNOTAP[M];//elements that are not present in the given sequence9 BOOLfirstout;Ten  One voidPrintintx) {//output Format Control PS: tested on CF, regardless of the format can be AC A     if(firstout) { -printf"%d", x); -Firstout =false; the     }   -     Else -printf"%d", x); - } +  - intMain () { +      while(~SCANF ("%d", &N)) { Amemset (Mark,0,sizeof(Mark)); atmemset (Notap,0,sizeof(Notap)); -          for(intI=1; i<=n; i++ )   { -scanf"%d", A +i); -mark[a[i]]++; -         } -         intCNT =1; in          for(intI=1; i<=n; i++ ) -             if( !Mark[i]) { toNOTAP[CNT] =i; +cnt++; -             } theFirstout =true; *         inttop =1; $          for(intI=1; i<=n; i++ )Panax Notoginseng             if(Mark[a[i]] = =1&& A[i] <= N)//this number is in the given sequence and the range is valid - print (a[i]); the             Else    { +Print (Notap[top]);//Otherwise, a number is ejected from the sequence that is not Atop++; themark[a[i]]--; +             } -printf"\ n"); $     } $     return 0; -}

Codeforces Round #315 (Div. 2) 569B Inventory

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.