A.MEX Table
思路:读完题后发现题意还是很简单的,在解决前需要观察一下。
在纸上自己写一两个例子,就能发现其实最终结果只与‘0’所在的列和行有关,其余全是0,再观察发现‘0’所在的一行或者一列有其一的值必是1,那要使结果最大只能对例一列或行想办法,当其为一个序列时是最优的,所以我们只要比较一下n,m的值就能得改列或行取值为n或者m,加上1就为答案。
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n, m, k;
cin >> n >> m;
cout << max(n,m)+1 << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
B.Gorilla and the Exam
思路:读完题后发现只需对在消除最少的种类的k个数后,统计有多少不同的种类就行,在消除k个数时仔细一点就行。
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
void solve()
{
int n, m, k;
cin >> n >> k;
vector<int> a(n);
map<int, int> mp;
for (int i = 0; i<n; i++){
cin >> a[i];
mp[a[i]]++;
}
deque<int> v;
for (auto [a, b]:mp){
v.push_back(b);
}
sort(v.begin(), v.end());
while (k>0 && v.size()>1){
int t = v.front();
v.pop_front();
int yu = t-min(k, t);
if (yu > 0) v.push_back(yu);
k-=min(k, t);
}
cout << v.size() << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}