#include #include #include <unordered_map> #include using namespace std;

int main() { int n, k; cin >> n >> k; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } unordered_map<int, int> count; for (int i = 0; i < n; i++) { count[a[i]]++; } int max_count = 0; for (auto it = count.begin(); it != count.end(); it++) { max_count = max(max_count, it->second); } int ans = 0; for (auto it = count.begin(); it != count.end(); it++) { if (it->second == max_count) { ans++; } } if (ans == 1 && k == 1) { cout << "pigstd" << endl; } else { cout << ans << endl; } return 0;

给定一个长度为 n 的序列 a我们通过以下方式构造序列:初始时 b=a。依次对 b 进行 k 次操作每次操作选择任意一个元素并将其修改为任意整数。一个序列的众数为所有出现次数最大的数你需要求出有多少整数可能成为 b 的众数。第一行输入两个整数 nk。第二行输入 n 个整数 a 输出一个整数代表可能成为众数的数的数量。特别地如果答案为正无穷输出 pigstd。 C++做法

原文地址: http://www.cveoy.top/t/topic/h5qG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录