首页 > 其他分享 >CF1552B Running for Gold

CF1552B Running for Gold

时间:2024-01-21 09:23:14浏览次数:21  
标签:比赛 Gold int 选手 leq Running CF1552B 数组 战胜

CF1552B Running for Gold

题目传送门

题面

奥运比赛刚刚开始,Federico 便十分渴望观看比赛。

有 \(n\) 个选手参加了马拉松比赛,从 \(1\) 到 \(n\) 依次编号。她们参加了 \(5\) 项比赛,比赛从 \(1\) 到 \(5\) 编号。

现在有一个二维的数组 \(r_{i,j}(1 \leq i \leq n,1 \leq j \leq 5)\),表示选手 \(i\) 在比赛 \(j\) 中排名第 \(r_{i,j}\) 名。

Federico 认为选手 \(u\) 优于选手 \(v\),当且仅当,\(u\) 在至少 \(3\) 个项目中战胜了 \(v\)(即排名在 \(v\) 前)。

Federico 认为选手 \(x\) 能够获得金牌当且仅当 \(x\) 可以战胜其它所有选手。

给定 \(r_{i,j}\),求是否有一名选手可以获得金牌。

思路

题目中仅要求输出一名即可,所以为了保证尽可能快的锁定这一名,可以先对每一个选手进行一个排序,按照一个人能否战胜另一个人为比较条件

虽然获胜不具备传递性(即A胜B,B胜C,但是A不一定胜C),但是如果按照上述方法进行排序,那么第一个人一定是最有可能获得金牌的,而不是一定能获得金牌

所以,当排完序后,再对第一个人进行一个检查,看看他能否战胜其余所有人即可

代码

我们可以建两个数组,一个存储比赛结果(\(a\)),另一个负责索引(\(r\)),即\(a_{i,j}\)表示选手\(i\)在比赛\(j\)中排名第\(r_{i,j}\)名,而\(r_i\)是排序数组,表示当前位于第\(i\)个位置的运动员在\(a\)数组中的编号

所以最后对\(r\)进行排序,再用cmp进行判断,看看两个\(r\)数组中对应的两个运动员能否战胜彼此,依据就是\(a\)数组(具体实现可以看代码)

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int Maxn=5e4+10;
int a[Maxn][10];
int r[Maxn];
int flag,n;
bool cmp(int x,int y)
{
    int num=0;
    for(int i=1;i<=5;i++) num+=(a[x][i]<a[y][i]);
    return num>=3;
}
void run()
{
    cin>>n;flag=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=5;j++)
        {
            cin>>a[i][j];
            r[i]=i;
        }
    sort(r+1,r+n+1,cmp);
    for(int i=2;i<=n && flag;i++)
        if(!cmp(r[1],r[i])) flag=0;
    cout<<(flag?r[1]:-1)<<endl;
    return;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--) run();
    system("echo. & pause");
    return 0;
}

标签:比赛,Gold,int,选手,leq,Running,CF1552B,数组,战胜
From: https://www.cnblogs.com/lyk2010/p/17977515

相关文章

  • Dithered golden interleaver 黄金分割伪随机交织器 代码备份
    目录公式来源DitheredgoldeninterleaverTheMatrix-DitheredGoldenInterleavingAlgorithm有错误欢迎指正公式来源DesignofaModifiedInterleavingAlgorithmBasedonGoldenSectionTheoryEnhancingthePerformanceofTurboCodesDitheredgoldeninterleaver(*......
  • 【解决方案】Error running,Command line is too long
    一、现象IDEA提示Errorrunning,Commandlineistoolong二、原因Java命令行启动举例如下图,当命令行字符过多的时候,就会出现Errorrunning,Commandlineistoolong的问题三、解决思路上图是最终解决方案,下文会再次出现。现在主要是讲解none、JARmanifest是什......
  • 讲解'BatchNorm2d' object has no attribute 'track_running_stats'
    讲解'BatchNorm2d'objecthasnoattribute'track_running_stats'在使用深度学习框架PyTorch进行模型训练时,有时可能会遇到以下错误提示:plaintextCopycode'BatchNorm2d'objecthasnoattribute'track_running_stats'这个错误提示通常与PyTorch版本升级或代码中的一些配......
  • Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docke
    CannotconnecttotheDockerdaemonatunix:///var/run/docker.sock.Isthedockerdaemonrunning?错误解决办法解决:从启动服务器1.systemctldaemon-reload2.systemctlrestartdocker.servicesystemctlrestartdocker.serviceCannotconnecttotheDockerdaemonatu......
  • hdfs报错:There are 0 datanode(s) running and 0 node(s) are excluded in this opera
    namenode的日志还是打印Thereare0datanode(s)runningand0node(s)areexcludedinthisoperation.吗 报错信息如下所示。其中,【X】是当前正在运行的DataNode数量,【Y】是被排除在此操作之外的DataNode数量。问题原因该问题表示在当前的集群状态下,因为无法满足文件的......
  • Redis报错:(error) DENIED Redis is running in protected mode because protected mod
    一、报错内容  (error)DENIEDRedisisrunninginprotectedmodebecauseprotectedmodeisenabledandnopasswordissetforthedefaultuser.Inthismodeconnectionsareonlyacceptedfromtheloopbackinterface.Ifyouwanttoconnectfromexternal......
  • The IDE is running low on memory
    WebStorm内存不足提示:TheIDEisrunninglowonmemoryandthismightaffectperformance.Pleaseconsiderincreasingtheheapsize.翻译:IDE内存不足,这可能会影响性能。请考虑增加堆大小。手动改大......
  • install goldendict-ng-git
    manjaro升级后,goldendict不能启动了,重新安装总是出错,原来是官方的版本不支持qt6了,查阅archlinux文档,获知goldendic-ng-git支持qt6,安装步骤如下,需要的同学可以参看。1.获取PKGBUILD文件,gitclone https://aur.archlinux.org/goldendict-ng-git.git2.安装必须的依赖,可能有......
  • springboot 启动命令过长问题处理(Error running 'xxxxApplication': Command line is
      翻译搜索复制......
  • [Mac软件]Goldie App v2.2 Mac黄金比例设计工具
    Goldie应用程序是在Mac上测量和可视化黄金比例的最佳方式。从比率的任何一点进行计算,在该行的各个主题之间切换,并自定义您如何使用Goldie。这个紧凑的工具将帮助您轻松创建完美平衡的设计。灵活的尺子Goldie应用程序在您的屏幕上显示一把尺子,这简化了与黄金比例的和解。适应背景颜......