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