(第六场)Singing Contest 【模拟】

企业数字化转型AI大模型赋能智能体平台及AI场景应用规划方案(生态合作版).pptx 立即下载

题目链接:https://www.nowcoder.com/acm/contest/144/A

标题:A、Singing Contest

| 时间限制:1 秒 | 内存限制:256M

Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating in the contest. The rule of this contest is like the knockout match. That is, in the first round, singer 1 competes with singer 2, singer 3 competes with singer 4 and so on; in the second round, the winner of singer 1 and singer 2 competes with the winner of singer 3 and singer 4 and so on. There are n rounds in total. Each singer has prepared n songs before the contest. Each song has a unique pleasantness. In each round, a singer should sing a song among the songs he prepared. In order not to disappoint the audience, one song cannot be performed more than once. The singer who sings the song with higher pleasantness wins. Now all the singers know the pleasantness of songs prepared by all the others. Everyone wants to win as many rounds as he can. Assuming that singers choose their song optimally, Jigglypuff wants to know which singer will win the contest?
输入描述: The input starts with one line containing exactly one integer t which is the number of test cases. (1 ≤ t ≤ 10)

For each test case, the first line contains exactly one integer n where 2n is the number of singers. (1 ≤ n ≤ 14)

Each of the next 2n lines contains n integers where aij is the pleasantness of the j-th song of the ith singer. It is guaranteed that all these 2nx n integers are pairwise distinct. (1≤ aij ≤ 109)

输出描述: For each test case, output "Case #x: y" in one line (without quotes), where x is the test case number (starting from 1) and y is the index of the winner.

示例 1

输入

2

1

1

2

2

1 8

2 7

3 4

5 6

输出

Case #1: 2

Case #2: 4

 

题意概括:

歌唱比赛,有2^N位歌手,每位歌手准备N首歌,每首歌可以得到的分数不同,每首歌只能唱一次。1和2比,3和4比...赢了的继续比下去,问最后谁会获胜。每位歌手的歌曲得分用一个二维矩阵表示,A[ i ][ j ]表示第 i 位歌手唱第 j 首歌可以得到的分数。

官方题解:

由于每个选⼿手的策略略都是尽可能赢,所以他该认输的时候只能认输。
能赢的时候只要选权值⼤大于对⽅方最⼤大值的最⼩小值,⼤大的留留在后⾯面不不会 更更差。
直接模拟即可。

解题思路:

每次对决,遵循贪心的原则,排序之后lower_bound()可以打败对手的最小值,遍历对决可以用DFS二分一下。

 

AC code:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 const int MAXN = (1<<14)+15;
 5 int f[MAXN][15];
 6 int N;
 7 
 8 int dfs(int l, int r)
 9 {
10     if(r == l+1)
11     {
12         sort(f[l], f[l]+N);
13         sort(f[r], f[r]+N);
14         int a = lower_bound(f[l], f[l]+N, f[r][N-1])-f[l];
15         int b = lower_bound(f[r], f[r]+N, f[l][N-1])-f[r];
16         if(a == N)
17         {
18             f[r][b] = 0;
19             return r;
20         }
21         else
22         {
23             f[l][a] = 0;
24             return l;
25         }
26     }
27     else
28     {
29         int mid = (l+r)>>1;
30         int x = dfs(l, mid);
31         int y = dfs(mid+1, r);
32         sort(f[x], f[x]+N);
33         sort(f[y], f[y]+N);
34         int a = lower_bound(f[x], f[x]+N, f[y][N-1])-f[x];
35         int b = lower_bound(f[y], f[y]+N, f[x][N-1])-f[y];
36         if(a == N)
37         {
38             f[y][b] = 0;
39             return y;
40         }
41         else
42         {
43             f[x][a] = 0;
44             return x;
45         }
46     }
47 }
48 
49 int main()
50 {
51     int T_case;
52     scanf("%d", &T_case);
53     int cnt = 0;
54     while(T_case--)
55     {
56         scanf("%d", &N);
57         for(int i = 1; i <= (1<<N); i++)
58             for(int j = 0; j < N; j++)
59         {
60             scanf("%d", &f[i][j]);
61         }
62         printf("Case #%d: %d\n", ++cnt, dfs(1, (1<<N)));
63     }
64     return 0;
65 }
View Code

 

Vivado加上VsCode让你的生活更美好 VsCode与Vivado的灵活使用 引言 ​ 现在大二了,在接触硬件描述语言。Vivado自带的编辑器实在很难用,为了能够“极客”一些,当然是去Google了一下有哪些方法可以取而代之。 ​ 网络上的答案大同小异,基本上都是用的Sublime Text.(我的学长们也几乎都是) 平时码代码的过程中,我习惯与使用VsCode,尤其是在微软收购GitHub之后,Code 简直就是神器了。于是乎…一个... 阅读详情

相关推荐

详解Numpy中的transpose方法

最近在学Numpy碰到了关于数组转置和换轴的概念,尤其是对tanspose方法有些疑惑,尤其是多维,查了不少资料,终于搞懂了。 Numpy数组的轴(axis) 所谓的**轴(axis)**可以理解为数组的维度。 具体而言,二维数组就是有两个维度,如果从空间上看,它就是一个平面,由x轴和y轴构成,而与此相对应的,该二维数组就有两个轴,x轴对应0轴,y轴对应1轴。 同理,三维数组有三个维度,空间上...

BlankGrid的博客 940

singing contest——(vector(水题))

链接:https://www.nowcoder.com/acm/contest/144/A 来源:牛客网   题目描述 Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating in the contest. The rule of this contest ...

20164225的博客 511

MacBook用户必看:用Homebrew一键搞定frp内网穿透(含阿里云配置模板)

本文为MacBook用户提供基于Homebrew的frp内网穿透实战指南,详细介绍了从环境准备到阿里云服务器配置的全过程。通过Homebrew一键安装frp客户端,结合阿里云配置模板,实现高效稳定的内网穿透,适用于远程开发、IoT设备调试等多种场景。

weixin_28692817的博客 322

Singing_Contest_( 结构体_数组 )

题目链接 题目描述 Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating in the contest. The rule of this contest is like the knockout match. That is, in the first ...

Z_sea的博客 863

金蝶K3系统物料主数据后台表对应字段一览

我们说到物料表,一般是指t_icitem,但正确的说t_icitem并不是一张有,而是一张视图,不过我们对于数据库物料表中的大部分操作,都是通过此视图来完成。比如经常通过此视图,来成批修改数量,单价精度,是否启用批次等一些字段,有的时候,对于账套已经启用,并且已经有业务发生的物料,有一些关键属性也需要通过修改物料表t_icitem来进行。 当然修改的时候,需要考虑一些前提条件的。 比如说我有一个客户新建的账套,在月底结账时发现,要改一种成本核算方法,启用时用的是加权平法,现在想改成移动平均法,这样的情况,

hzfw2008的博客 1万+

在Cursor IDE中集成Datadog监控:自然语言查询实战指南

在云原生和微服务架构中,可观测性(Observability)已成为保障系统稳定性的核心技术支柱。其核心原理是通过日志(Logs)、指标(Metrics)和追踪(Traces)三大支柱,实时采集并呈现系统的运行状态。这项技术的价值在于,它让开发者能够透视复杂的分布式系统,快速定位性能瓶颈与故障根因。在实际的工程实践中,开发人员常常需要在编码环境与监控平台之间频繁切换,这种上下文切换严重影响了排障效率。本文聚焦于如何利用Model Context Protocol(MCP),将强大的Datadog可观测性平台

weixin_42519772的博客 348

牛客网暑期ACM多校训练营(第六场)A Singing Contest(二分+队列)

链接:https://www.nowcoder.com/acm/contest/144/A 来源:牛客网   时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Jigglypuff is holding a singing contest. There are 2n singers i...

辞树 443

【思考模型框架】MECE原则,确保分析时,考虑到的所有因素,既不重叠又无遗漏

MECE原则,是Mutually Exclusive and Collectively Exhaustive的缩写,中文译为“相互独立、完全穷尽”。MECE原则,这是一种逻辑思维和组织信息的方法,旨在确保分析时既没有遗漏也没有重复。MECE原则,相互独立、完全穷尽(Mutually Exclusive,Collectively Exhaustive)的原则MECE原则,确保分析时考虑到的所有因素既不重叠又无遗漏。

奶爸的编程之路,也就一周冷个三天 2756

Singing Contest

这题debug了3个小时,当时简直崩溃........ 题意   : 有2^n个歌手进行比赛,每位歌手准备好了n首歌,每首歌的愉悦度都不一样,每位歌手都知道对方每首歌的愉悦度,并且愉悦度越高的就会赢,输了的直接淘汰,为了尽可能的多进行几场比赛(赛制为两两相互比赛),歌手每场都会从低到高选出第一个大于对方歌手的歌来进行比赛,对于选值操作在judge函数里,我用的是二分查找的lower_bound...

茗少的博客 6155

基于BEV(鸟瞰图)的3D检测:PointPillars与CenterPoint

基于BEV(鸟瞰图)的3D检测:PointPillars与CenterPoint​ ,人工智能,计算机视觉,大模型,AI,本文围绕基于BEV的3D检测,解析了PointPillars与CenterPoint两种算法。PointPillars用点柱特征编码网络处理点云,通过2D卷积网络提取特征,检测头为解耦头;CenterPoint将三维物体表为点,分两阶段检测,先找中心点及属性,再细化预测。两者都可借特定骨干网生成BEV特征图且基于BEV检测,但检测头设计和物体表示方式不同。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 27万+

PDBfixer:蛋白质结构修复工具

本文介绍蛋白质数据银行(PDB)文件常见问题及修复工具PDBFixer的使用方法。PDB文件常存在缺失原子、残基等问题,PDBFixer可通过GUI、命令行或Python API实现自动化修复。文章详细说明安装方法、命令行参数、Python脚本修复流程及非标准残基替换表,并与Modeller、ColabFold和Rosetta Remodel等其他修复工具进行对比分析,提供了各工具的特点、适用场景和典型计算时间比较,帮助用户根据具体需求选择合适的修复工具。

Protein Designer的博客 613

牛客网暑期ACM多校训练营(第六场)A Singing Contest 队列 +简单模拟

链接:https://www.nowcoder.com/acm/contest/144/A 来源:牛客网   Singing Contest 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Jigglypuff is holding a singing contest. There...

qq_41668093的博客 364

使用virtuoso gds转lef操作方法

2) 然后,需要创建Pin,这里Pin的概念不同于label/text,是有实际金属的,二者的区别类似于pr中的port和terminal。1) 首先,需要画prBoundary,这个用drawing层的prBoundary画是不行的,不过建议pr阶段就把prBoundary转到gds里,在virtuoso layout中画prBoundary就比较容易。另外,用Create - Create Pin也可以创建pin,更适用于PG pin,操作时先给pg shape打label,最好放正中间。

m0_61544122的博客 1383

牛客网暑期ACM多校训练营(第六场)--- A题 Singing Contest (疯狂模拟)

A题  Singing Contest 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述  Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating ...

mzt_twilignt的博客 323

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

@2018 牛客网暑期ACM多校训练营(第六场): A:Singing Contest (队列模拟)

链接:https://www.nowcoder.com/acm/contest/144/A 来源:牛客网   Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating in the contest. The rule of this contest is lik...

Sizaif's 小屋 310

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

牛客多校第六场 Singing Contest

链接:https://www.nowcoder.com/acm/contest/144/A 来源:牛客网   时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Jigglypuff is holding a singing contest. There are 2n singers i...

gtuif的博客 445

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

牛客网暑期ACM多校训练营(第六场)A-Singing Contest

时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating in the contest. The ru...

shiyuKirito的博客 269

A Singing Contest

牛客网暑期ACM多校训练营(第六场) A Singing Contest 题目: 链接:https://www.nowcoder.com/acm/contest/144/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述 Jigglypuff is holding ...

weixin_30709635的博客 363

牛客网暑期ACM多校训练营(第六场)Singing Contest

链接:https://www.nowcoder.com/acm/contest/144/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Jigglypuff is holding a singing contest. There are 2n singers...

qq_42515626的博客 383

牛客网暑期ACM多校训练营(第六场)A(Singing Contest)

题目描述  Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating in the contest. The rule of this contest is like the knockout match. That is, in the first round...

snayf的博客 194

牛客网暑期ACM多校训练营(第六场) A Singing Contest

题目链接: https://www.nowcoder.com/acm/contest/144/A 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld 题目描述 Jigglypuff is holding a singing contest. There are 2nsingers indexe...

weixin_34329187的博客 89

ARM架构入门:从RISC原理到虚拟机、交叉编译的实践路线

在PC、手机与嵌入式设备交织的今天,CPU指令集架构成为理解软硬件生态的关键分水岭。x86与ARM分别代表CISC和RISC两大路线:前者指令复杂、硬件负担重,后者以精简指令、load/store架构和丰富寄存器为特色,在能效比与可扩展性上占据优势。从ARMv7到ARMv9、从Cortex-A/M/R到AArch64,版本名词背后是统一的架构演进逻辑。理解这些概念,不仅能解释VMware中ARM选项为何无法直接安装amd64镜像、ventoy需要专用ARM版本,也能指导开发者在树莓派或Apple Silic

weixin_33827731的博客 372

2018牛客网暑假ACM多校训练赛(第六场)A Singing Contest 两两比赛问最终胜者的递归

题目传送门:https://www.nowcoder.com/acm/contest/144/A 题意: 2^n个歌手,每个歌手可以从自己的n首歌里选一首,每首歌对应一个评分,但选过的不能再选。 现在1号和2号,3号和4号……2^n-1和2^n比赛。淘汰赛,输一局即被淘汰。赢者再两两比赛,问最终胜者。 题解: 贪心+递归+STL ①我们只需在自己比对方最大的数还大的数里面,选择里面最小...

小衣同学的博客 527

A Singing Contest(六)

链接:https://www.nowcoder.com/acm/contest/144/A 来源:牛客网   时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Jigglypuff is holding a singing contest. There are 2n singers i...

d1183的博客 640

牛客网多校赛6 ASinging Contest (数据结构应用+模拟)

链接:https://www.nowcoder.com/acm/contest/144/A 来源:牛客网   题目描述 Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating in the contest. The rule of this contest ...

满月照亮的路 301
上一篇: POJ 3621 Sightseeing Cows 【01分数规划+spfa判正环】
下一篇: (第六场)Heritage of skywalkert 【玄学】
莜莫oO
博客等级 码龄9年 7粉丝 226原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值