题解:P17298 [ICPC 2026 Xi'an I] Registration
patata_frita · · 题解
签到题。
题目大意
给出
题目思路
我们注意到报名时间的范围过大,无法使用数组存储,考虑使用离散化或 map 映射。由于 map 更简洁且本题不卡时间,爱偷懒的我们果断使用 map 进行操作。每次读入一支队伍的报名时间就记录,最后遍历所有有队伍报名的时刻进行计算。
:::success[AC 代码:]
#include <iostream>
#include <map>
using namespace std;
int n, t, x, v, ans;
map<int, int> a;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--)
{
ans = 0;
a.clear();
cin >> n >> x;
for (int i = 1; i <= n; i++)
{
cin >> v;
a[v]++;
}
for (auto i : a)
{
if (i.second <= x)
{
ans += i.second;
}
}
cout << ans << '\n';
}
return 0;
}
:::