【Hash】【Boyer-Moor】Colorful Balloons
今天和ssy吃饭,他和我说拉美赛区题目质量不一定好,所以开始做icpc2023 合肥题目
https://codeforces.com/gym/104857/problem/F
这是他当时写的签到题,用Boyer-Moor
投票法可以很轻松地搞定,但是他建议我用朴实的方法,因为空间不重要
学会了使用for(const auto& pair:mymap){pair.first, pair.second}
来遍历哈希的键和值,挺好用的
#include <iostream>
#include <map>
#include <string>
int main() {
int n;
std::cin >> n;
std::map<std::string, int> colorCount;
std::string color;
// Reading colors and counting occurrences
for (int i = 0; i < n; i++) {
std::cin >> color;
colorCount[color]++;
}
// Determine the color that appears more than n / 2 times
for (const auto& pair : colorCount) {
if (pair.second > n / 2) {
std::cout << pair.first << std::endl;
return 0; // Found the majority color, exit program
}
}
// If no majority color is found
std::cout << "uh-oh" << std::endl;
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)