Codeforces-- Hello 2025

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wirepuller_king

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值