Content

有 \(n\) 场已经进行完的赛车比赛,每场比赛给出前 \(m\) 名的名字。在每场比赛中,前 \(10\) 名的选手分别可以获得 \(25,18,15,12,10,8,6,4,2,1\) 分,其他名次的选手不得分。现在给出两种排序方式:

  1. 先按照得分降序排序,如果得分相同,按照得到第一名的次数降序排序,如果还是相同,就按照得到第二名的次数降序排序,以此类推,直到比较出来为止。
  2. 先按照得到第一名的次数降序排序,如果次数相同,按照得分降序排序,如果还是相同,就按照得到第二名的次数降序排序,以此类推,直到比较出来为止。

请求出按照两种排序方式排序之后分别得出来的第一名。

数据范围:\(1\leqslant n\leqslant 20,1\leqslant m\leqslant 50\)。

Solution

结构体排序好题。

我们开个结构体,把每个人的名字、得分以及得到的名次的次数情况储存下来:

struct player {
string name;
int score, ranking[57];
}a[1007], b[1007];

然后就是如何通过输入储存了,我们还是利用 \(\texttt{map}\) 将每个人的名字映射到其编号上,每出现一个新的名字,就新开一个空间来存储,并统计这个人的分数和排名情况。

那么为什么要开两组结构体呢?这样好方便排序,所以我们再复制一组相同的结构体,然后按照上面的两个排序方式排序即可,可以写两个 \(\texttt{cmp}\) 函数,然后直接按照上面的方式模拟即可。

Code

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <map>
using namespace std; const int getscore[51] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> vis;
int n, cnt;
string names;
struct player {
string name;
int score, ranking[57];
}a[1007], b[1007]; bool cmp1(const player& p1, const player& p2) {
if(p1.score != p2.score) return p1.score > p2.score;
else
for(int i = 1; i <= 50; ++i)
if(p1.ranking[i] != p2.ranking[i]) return p1.ranking[i] > p2.ranking[i];
}
bool cmp2(const player& p1, const player& p2) {
if(p1.ranking[1] != p2.ranking[1]) return p1.ranking[1] > p2.ranking[1];
else if(p1.score != p2.score) return p1.score > p2.score;
else
for(int i = 2; i <= 50; ++i)
if(p1.ranking[i] != p2.ranking[i]) return p1.ranking[i] > p2.ranking[i];
} int main() {
scanf("%d", &n);
while(n--) {
int m;
scanf("%d", &m);
for(int i = 1; i <= n; ++i) {
cin >> names;
if(!vis[names]) {
vis[names] = ++cnt;
a[vis[names]].name = names;
}
a[vis[names]].score += getscore[i];
a[vis[names]].ranking[i]++;
}
}
for(int i = 1; i <= cnt; ++i) b[i] = a[i];
sort(a + 1, a + cnt + 1, cmp1);
sort(b + 1, b + cnt + 1, cmp2);
cout << a[1].name << endl << b[1].name;
return 0;
}

CF24B F1 Champions 题解的更多相关文章

  1. CodeForces 24B F1 Champions(排序)

    B. F1 Champions time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  2. 24B F1 Champions

    传送门 题目 Formula One championship consists of series of races called Grand Prix. After every race driv ...

  3. hdu-4893

    http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意: 给定一个数组a,一开始数组里面的元素都是0,现在有三个操作: 操作1:给第k个数字加上d. 操作2 ...

  4. 靶形数独 (codevs 1174)题解

    [问题描述] 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向Z 博士请教,Z 博士拿出了他最近发明的“ ...

  5. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  6. usaco training 4.2.4 Cowcycles 题解

    Cowcycles题解 Originally by Don Gillies [International readers should note that some words are puns on ...

  7. NOIP 2014 提高组 题解

    NOIP 2014 提高组 题解 No 1. 生活大爆炸版石头剪刀布 http://www.luogu.org/problem/show?pid=1328 这是道大水题,我都在想怎么会有人错了,没算法 ...

  8. bzoj usaco 金组水题题解(2.5)

    bzoj 2197: [Usaco2011 Mar]Tree Decoration 树形dp..f[i]表示处理完以i为根的子树的最小时间. 因为一个点上可以挂无数个,所以在点i上挂东西的单位花费就是 ...

  9. P1962 斐波那契数列-题解(矩阵乘法扩展)

    https://www.luogu.org/problemnew/show/P1962(题目传送) n的范围很大,显然用普通O(N)的递推求F(n)铁定超时了.这里介绍一种用矩阵快速幂实现的解法: 首 ...

随机推荐

  1. CSS Web Fonts 网络字体

    Fonts 1. CSS font-family 在 CSS 中,可以使用 font-family 属性来指定字体,浏览器渲染文字时候会根据这个属性应用于元素.如果没有指定这个属性或者指定的字体不存在 ...

  2. 状压DP详解+题目

    介绍 状压dp其实就是将状态压缩成2进制来保存 其特征就是看起来有点像搜索,每个格子的状态只有1或0 ,是另一类非常典型的动态规划 举个例子:有一个大小为n*n的农田,我们可以在任意处种田,现在来描述 ...

  3. 洛谷 P4621 - [COCI2012-2013#6] BAKTERIJE(exCRT)

    洛谷题面传送门 发篇正常点的题解. 首先对于这样的题暴力枚举肯定是不行的,因为最小时间显然可能达到 \((4nm)^5\approx 10^{20}\),就算数据很难卡到这个上界,构造出一些使你暴力超 ...

  4. 模仿UP主,用Python实现一个弹幕控制的直播间!

    灵感来源 之前在B站看到一个有意思的视频: [B站][亦]终极云游戏!五千人同开一辆车,复现经典群体智慧实验 大家可以看看,很有意思. up主通过代码实现了实时读取直播间里的弹幕内容,进而控制自己的电 ...

  5. 【豆科基因组】大豆(Soybean, Glycine max)泛基因组2020Cell

    目录 一.前沿概述 二.主要结果 重测序.组装与注释 泛基因组 SV特征 PAV与古多倍化,WGD事件 基因SV与基因融合 SV与大豆驯化 SV影响基因表达及其与性状关联 一.前沿概述 Pan-Gen ...

  6. 25-ZigZag Conversion

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  7. PC端申请表

    公司项目需求中要做用html做一个PDF申请表的样式出来.有点意思,贴上来大家看看. 先上效果图: 附上源代码: HTML:<div id="form"> <h2 ...

  8. Celery进阶

    Celery进阶 在你的应用中使用Celery 我们的项目 proj/__init__.py   /celery.py   /tasks.py 1 # celery.py 2 from celery ...

  9. CentOS7 搭建maven私服Nexus

    下载解压 官网https://www.sonatype.com/download-oss-sonatype 下载页面 https://help.sonatype.com/repomanager2/do ...

  10. 【leetcode】917. Reverse Only Letters(双指针)

    Given a string s, reverse the string according to the following rules: All the characters that are n ...