[CF] C. Boxes Packing - Educational Codeforces Round 34 (Rated for Div. 2)
Solutions Codeforces 贪心 1200 Easy-
Lastmod: 2025-02-01 周六 23:32:47

https://codeforces.com/contest/903/problem/C

题目大意

给出 $n \ (\le 5000)$ 个数的数组 $a$ 其中 $1 \le a_i \le 10^9$。问最少可以把它分成多少个集合,使得每个集合都可以重排成一个严格单调递增的链。

简要题解

显然同样数值的数必然属于不同的链,因此最少不少于最大频率 $f_{max}$,而显然,对于频率为 $f_i$ 的数我们只需任意从 $f_{max}$ 组中选出 $f_i$ 组,然后每一个选出的放入 $1$ 个即可保证,所有组内的数字全部不重复。

复杂度

$T$:$O(n \log n)$

$S$:$O(n)$

代码实现

#include <bits/stdc++.h>
using namespace std;

int io_=[](){ ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();

using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
using VI = vector<int>;
using MII = map<int, int>;

template<typename T> void cmin(T &x,const T &y) { if(y<x) x=y; }
template<typename T> void cmax(T &x,const T &y) { if(x<y) x=y; }
template<typename T> bool ckmin(T &x,const T &y) { 
    return y<x ? (x=y, true) : false; }
template<typename T> bool ckmax(T &x,const T &y) { 
    return x<y ? (x=y, true) : false; }
template<typename T> void cmin(T &x,T &y,const T &z) {// x<=y<=z 
    if(z<x) { y=x; x=z; } else if(z<y) y=z; }
template<typename T> void cmax(T &x,T &y,const T &z) {// x>=y>=z
    if(x<z) { y=x; x=z; } else if(y<z) y=z; }

// mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
// mt19937_64 rnd_64(chrono::system_clock::now().time_since_epoch().count());

/*
---------1---------2---------3---------4---------5---------6---------7---------
1234567890123456789012345678901234567890123456789012345678901234567890123456789
*/

void solve() {
  int n; cin >> n;
  vector<int> a(n);
  for (int& i : a) cin >> i;

  map<int, int> cnt;
  for (int i : a) cnt[i]++;

  int mx = 0;
  for (auto [v, c] : cnt) {
    cmax(mx, c);
  }
  cout << mx << '\n';
}

int main() {
  int t = 1; 
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Prev: [CF] C. Slay the Dragon - Educational Codeforces Round 114 (Rated for Div. 2)
Next: [CF] D. Almost Difference - Educational Codeforces Round 34 (Rated for Div. 2)