Greedy bestcoder Round #39 1001 Delete

Source: Internet
Author: User

Topic Portal

1 /*2 Greedy water problem: Find out the number of occurrences >1 and res, if you want to subtract smaller than res, then the total number of different tot will not be less;3 or subtract the excess in tot as the answer.4 you can do it with a set container, like the idea .5 */6#include <cstdio>7#include <iostream>8#include <cstring>9#include <string>Ten#include <algorithm> One using namespacestd; A  - Const intMAXN = 1e4 +Ten; - Const intINF =0x3f3f3f3f; the intcnt[ the]; -  - intMainvoid)//bestcoder Round #39 1001 Delete - { +     //freopen ("1001.in", "R", stdin); -  +     intN; A      while(SCANF ("%d", &n) = =1) at     { -         intK; -memset (CNT,0,sizeof(CNT)); -  -         inttot =0, res =0, X; -          for(intI=1; i<=n; ++i) in         { -scanf ("%d", &x); to             if(Cnt[x] = =0) tot++; +             Else if(Cnt[x] >=1) res++; -cnt[x]++; the         } *  $scanf ("%d", &k);Panax Notoginseng         if(res >= k) printf ("%d\n", tot); -         Elseprintf ("%d\n", Tot-(K-res)); the     } +  A     return 0; the}
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <string>5#include <algorithm>6#include <Set>7 using namespacestd;8 9 intMainvoid)//bestcoder Round #39 1001 DeleteTen { One     //freopen ("1001.in", "R", stdin); A  -     Set<int>S; -     intN, K; the  -      while(Cin >>N) -     { - s.clear (); +         intx; -          for(intI=1; i<=n; ++i) +         { ACIN >>x; S.insert (x); at         } -  -CIN >>K; -cout << ((N-s.size () <= k)? N-k: S.size ()) <<Endl; -     } -  in     return 0; -}
using the Set container

Greedy bestcoder Round #39 1001 Delete

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.