做完这道题我深刻的意识到了我是区这件事。
我是可爱的区区区。
思路
要求数组的 ,只需在 中存在一个整数完全不在数组中出现。
把某个数彻底删去的代价等于该数的出现次数,所以只需在 中找到出现次数的最小值,就是最少的删除操作次数。
AC code
#include <bits/stdc++.h>
#define int long long
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 4e6 + 7;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
// const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
// const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int dx[] = {-1 , 1 , 0 , 0} ;
const int dy[] = {0 , 0 , -1 , 1} ;
inline int read ()
{
int s = 0 , w = 1 ;
char ch = getchar () ;
while (ch < '0' || ch > '9')
{
if (ch == '-')
w = -1;
ch = getchar () ;
}
while (ch >= '0' && ch <= '9')
{
s = s * 10 + ch - '0' ;
ch = getchar ();
}
return s * w ;
}
inline void write (int x)
{
if (x < 0) putchar ('-') , x = -x ;
if (x > 9) write (x / 10) ;
putchar (x % 10 + '0') ;
return ;
}
int a[N] , b[N] ;
int ans = INF ;
signed main()
{
fst ;
int n , k ;
cin >> n >> k ;
for (int i = 1 ; i <= n ; i ++)
{
cin >> a[i] ;
b[a[i]] ++ ;
}
for (int i = 0 ; i <= k ; i ++)
{
ans = min(ans , b[i]) ;
}
cout << ans ;
return 0;
}