(第六场)Singing Contest 【模拟】
题目链接: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:
#include <bits/stdc++.h>
using namespace std; const int MAXN = (<<)+;
int f[MAXN][];
int N; int dfs(int l, int r)
{
if(r == l+)
{
sort(f[l], f[l]+N);
sort(f[r], f[r]+N);
int a = lower_bound(f[l], f[l]+N, f[r][N-])-f[l];
int b = lower_bound(f[r], f[r]+N, f[l][N-])-f[r];
if(a == N)
{
f[r][b] = ;
return r;
}
else
{
f[l][a] = ;
return l;
}
}
else
{
int mid = (l+r)>>;
int x = dfs(l, mid);
int y = dfs(mid+, r);
sort(f[x], f[x]+N);
sort(f[y], f[y]+N);
int a = lower_bound(f[x], f[x]+N, f[y][N-])-f[x];
int b = lower_bound(f[y], f[y]+N, f[x][N-])-f[y];
if(a == N)
{
f[y][b] = ;
return y;
}
else
{
f[x][a] = ;
return x;
}
}
} int main()
{
int T_case;
scanf("%d", &T_case);
int cnt = ;
while(T_case--)
{
scanf("%d", &N);
for(int i = ; i <= (<<N); i++)
for(int j = ; j < N; j++)
{
scanf("%d", &f[i][j]);
}
printf("Case #%d: %d\n", ++cnt, dfs(, (<<N)));
}
return ;
}
(第六场)Singing Contest 【模拟】的更多相关文章
- 牛客多校第六场 A Garbage 模拟/签到
题意: 给你一个字符串,代表一个垃圾都有哪些物质组成,再给你一个字符串,代表a-z代表的物质分别是有害物质,干物质还是湿物质,根据题目的定义,回答是什么垃圾. 题解: 根据题意模拟即可. #inclu ...
- NOI.AC NOIP模拟赛 第六场 游记
NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...
- 牛客多校对抗第6场 A Singing Contest
[20分]标题:A.Singing Contest | 时间限制:1秒 | 内存限制:256MJigglypuff is holding a singing contest. There are 2n ...
- 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard
山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...
- noi.ac 第五场第六场
t1应该比较水所以我都没看 感觉从思路上来说都不难(比牛客网这可简单多了吧) 第五场 t2: 比较套路的dp f[i]表示考虑前i个数,第i个满足f[i]=i的最大个数 i能从j转移需要满足 j< ...
- 2014 HDU多校弟六场J题 【模拟斗地主】
这是一道5Y的题目 有坑的地方我已在代码中注释好了 QAQ Ps:模拟题还是练的太少了,速度不够快诶 //#pragma comment(linker, "/STACK:16777216&q ...
- Gym.101908 Brazil Subregional Programming Contest(寒假自训第六场)
这几天睡眠时间都不太够,室友晚上太会折腾了,感觉有点累,所以昨天的题解也没写,看晚上能不能补起来. B . Marbles 题意:给定N组数(xi,yi),玩家轮流操作,每次玩家可以选择其中一组对其操 ...
- 多校第六场 HDU 4927 JAVA大数类+模拟
HDU 4927 −ai,直到序列长度为1.输出最后的数. 思路:这题实在是太晕了,比赛的时候搞了四个小时,从T到WA,唉--对算组合还是不太了解啊.如今对组合算比較什么了-- import java ...
- 2019牛客多校第六场 B - Shorten IPv6 Address 模拟
B - Shorten IPv6 Address 题意 给你\(128\)位的二进制,转换为十六进制. 每\(4\)位十六进制分为\(1\)组,每两组用一个\(":"\)分开. 每 ...
随机推荐
- innoback 参数及使用说明
--defaults-file 同xtrabackup的--defaults-file参数,指定mysql配置文件; --apply-log 对xtrabackup的--prepare参数的封装; - ...
- Fedora中安装VLC播放器
需要在机器上安装VLC,无奈不能直接通过yum安装,网上搜了一下,直接安装成功,其实挺简单的: 我的机器是Fedora15,其他的类似: ------------------------- 首先:su ...
- TOJ 2861 Octal Fractions
描述 Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0 ...
- ZwQueryVirtualMemory暴力枚举进程模块
0x01 前言 同学问过我进程体中EPROCESS的三条链断了怎么枚举模块,这也是也腾讯面试题.我当时听到也是懵逼的. 后来在网上看到了一些内存暴力枚举的方法ZwQueryVirtualMemory. ...
- Tomcat 启动很慢?
Tomcat 8启动很慢,在启动中, 发现加载如下类时很慢: org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom 原因 ...
- word 摘要
word 使用心得 定义快捷键 Tools -> Customize keyboard 自定义快捷键 cmd + L, 左对齐; cmd + R, 右对齐; cmd + E, 居中对齐 cmd ...
- JS异步执行之setTimeout 0的妙用
最近在工作中遇到一些问题,大致是关于js执行问题的.由于没搞清执行顺序,导致出现了一些奇怪的bug. 所以这里整理一些有关异步执行的知识(冰山一角角)... 大家都知道js是单线程的,执行起来是顺序的 ...
- [LeetCode]26. Remove Duplicates from Sorted Array删除排序数组中的重复项
Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...
- Android4.4 在Framework新增内部资源编译不过的问题
如果在Frameworks新增内部资源,并在Java代码中使用类似形式来引用资源:com.android.internal.R.layout.xxx,需要在frameworks/base/core/r ...
- Csharp: Detect Mobile Browsers
/// <summary> /// 檢測手機客戶端 HttpCapabilitiesBase.IsMobileDevice /// .NET 4.5 /// 塗聚文注 /// </s ...