题目链接: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

转载于:https://www.cnblogs.com/ymzjj/p/9438777.html

(第六场)Singing Contest 【模拟】相关推荐

  1. NOI.AC NOIP模拟赛 第六场 游记

    NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...

  2. 牛客网暑期ACM多校训练营(第六场) - (A,C,J)

    比赛链接:https://www.nowcoder.com/acm/contest/144#question A Singing Contest 题意:有编号1~2^n的2^n个人参加唱歌比赛,每人有 ...

  3. 2020杭电多校训练(第五、六场)

    目录 第五场 1001.Tetrahedron 1009.Paperfolding 1003.Boring-Game 1012.Set1 1007.Tree 第六场 1006.A-Very-Easy- ...

  4. 牛客第六场 H-Hopping Rabbit

    牛客第六场 H-Hopping Rabbit 给出平面上的n个矩形,一只兔子从(x0+0.5,y0+0.5)(x_0+0.5,y_0+0.5)(x0​+0.5,y0​+0.5)出发,每一次可以平行于x ...

  5. 2020牛客暑期多校训练营(第六场)

    2020牛客暑期多校训练营(第六场) 额,睡了一下午,直接错过了比赛... 文章目录 A African Sort 题意: 题解: 代码: B Binary Vector C Combination ...

  6. 杭电多校第六场个人补题6 7 9 10 12

    杭电多校第六场个人补题6 7 9 10 12 6 题意 给定一棵有n结点的树,点权为1~n,求对所有结点子树的mex操作和的最大值 思路 其实就是从最底部开始网上找,由于0是唯一的一个,所欲最好给在最 ...

  7. 题解报告(CDUT暑期集训——第六场)

    题解报告(CDUT暑期集训--第六场) A - oval-and-rectangle HDU - 6362 思路:水题 积分一化就出来了 AC代码 #include<stdio.h> #i ...

  8. 10h+技术干货 | 我们整理了过去六场机器人创新生态系列研讨会总结+专家干货,一次性带你看过瘾!

    2020年已经步入下半年,至今为止英特尔智能机器人产学研生态合作系列研讨会已完成了6场研讨会,在这总时长10h+的深度研讨会上,从智能零售为起点,走过人工智能.工业4.0.机器人.数据中台等多个领域, ...

  9. 2022湖南多校对抗赛第六场

    2022湖南多校对抗赛第六场 队伍排名 第一 第二 第三 湖南大学1队 湖南大学4队 中南大学2队 团体成绩 取每个学校正式队伍前四名 学校 总题数 湖南大学 16 中南大学 16 国防科技大学 16 ...

最新文章

  1. SpringMVC 静态资源CSS,JS访问不了 解决方法
  2. php中删除评论怎么做的,php实现评论回复删除功能
  3. 他们和机器人啪啪啪,并计划共度一生
  4. 市面主要远场语音交互技术架构
  5. 你的代码(软件)安全吗?【信息图】
  6. php如何获取文本中的换行符,如何获取字符里面的换行符
  7. Qt工作笔记-进程间的通信(通过QSharedMemory)
  8. vue 深度拷贝数组_前端深拷贝和浅拷贝
  9. 模糊查询(类似百度搜索框)
  10. 2020 年 9 月程序员工资统计,新出炉!
  11. 使用ViewModel模式来简化WPF的TreeView
  12. c语言警告文件末尾没有换行符,“文件末尾没有换行符”编译器警告
  13. Linux运维之道(大量经典案例、问题分析,运维案头书,红帽推荐)
  14. 强化学习用于电力系统决策与控制(一)——频率调整
  15. 一个简单标注库的插件化开发实践
  16. Dorado7自定义下拉框
  17. python罗马数字转换阿拉伯数字_罗马数字与阿拉伯数字转换
  18. YOLOv2原文解读
  19. 汇编语言基础--汇编操作指令概述
  20. 2017 年节点——T 型成长,持续学习

热门文章

  1. Leetcode 103.二叉树的锯齿形层序遍历
  2. 用stm32开发时是直接买现成的开发板还是芯片?开发板学习,芯片硬件设计
  3. Cortex-M0微处理器异常入口流程的细节
  4. 微软出资10亿美元研究AGI,意与谷歌竞争?
  5. Django多进程中的查询错乱问题以及mysql gone away问题
  6. pyqt 槽任意参数_PyQt5快速入门(二)PyQt5信号槽机制
  7. 天涯社区服务器位置,天涯到底怎么了,哪份帖子都打不开,是服务器的问题吗...
  8. html太极图代码静态_如何做URL静态化?和页面的静态化
  9. python数学知识_数学知识回顾01
  10. 计算机组成原理主存储器知识点,【考研】2020考研:计算机组成原理知识点主存储器与CPU的连接...