CF24B F1 Champions
题意
根据题意模拟排序,自己看吧。
解法
蓝题模拟,确实很容易。
搞个 map
记录每个人得分以及每个人的排名出现次数,cmp
函数很容易写,非常容易。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
constexpr int N(1e4 + 5);
int t, n;
map<pair<string, int>, int> p;
map<string, int> score;
int idx = 0;
set<string> st;
string a[N];
bool cmp1(string a, string b)
{
if (score[a] ^ score[b]) return score[a] > score[b];
for (int i = 1; i <= 50; i++)
{
if (p[make_pair(a, i)] ^ p[make_pair(b, i)]) return p[make_pair(a, i)] > p[make_pair(b, i)];
}
return true;
}
bool cmp2(string a, string b)
{
if (p[make_pair(a, 1)] ^ p[make_pair(b, 1)]) return p[make_pair(a, 1)] > p[make_pair(b, 1)];
if (score[a] ^ score[b]) return score[a] > score[b];
for (int i = 2; i <= 50; i++)
{
if (p[make_pair(a, i)] ^ p[make_pair(b, i)]) return p[make_pair(a, i)] > p[make_pair(b, i)];
}
return true;
}
int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
string s;
cin >> s;
p[make_pair(s, i)]++;
/*
* 25, 18, 15, 12, 10, 8, 6, 4, 2, 1
*/
if (i == 1) score[s] += 25;
else if (i == 2) score[s] += 18;
else if (i == 3) score[s] += 15;
else if (i == 4) score[s] += 12;
else if (i == 5) score[s] += 10;
else if (i == 6) score[s] += 8;
else if (i == 7) score[s] += 6;
else if (i == 8) score[s] += 4;
else if (i == 9) score[s] += 2;
else if (i == 10) score[s] += 1;
st.insert(s);
}
}
for (auto it = st.begin(); it != st.end(); ++it)
{
a[++idx] = *it;
}
sort(a + 1, a + idx + 1, cmp1);
cout << a[1] << endl;
sort(a + 1, a + idx + 1, cmp2);
cout << a[1] << endl;
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现