(第六场)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\)组,每两组用一个\(":"\)分开. 每 ...
随机推荐
- 枚举类型与字符串ConvertEnumToString
枚举类型与字符串添加字典互转ConvertEnumToString using UnityEngine; using System.Collections; using UnityEngine.UI; ...
- pjsip与QT进行适配
pjsip是纯C语言写的一个sip协议库,整个代码写得还是比较模块化的,得益于此的设计,只要理解了pjsip的设计,就可以对其网络层进行扩展. 我们项目是QT作为主要开发工具,而PJSIP的库默认是利 ...
- java连接redis使用jedis带密码
一.引入jedis的Maven配置文件 <!-- redis连接客户端jedis --> <dependency> <groupId>redis.clients&l ...
- Http编程之HttpClient
在Android开发中,Android SDK附带了Apache的HttpClient,它是一个完善的客户端.它提供了对HTTP协议的全面支持,可以使用HttpClient的对象来执行HTTP GET ...
- 网络连接和初始HTTP请求
浏览器检索网页,先从URL开始,使用DNS确定IP地址,再用基于TCP和HTTP协议连接到服务器,请求相关的内容,得到相应,浏览器解析并呈现到屏幕上.服务器响应后,浏览器响应不会同时全部到达,会陆续到 ...
- 深入理解JavaScript系列(9):根本没有“JSON对象”这回事!
前言 写这篇文章的目的是经常看到开发人员说:把字符串转化为JSON对象,把JSON对象转化成字符串等类似的话题,所以把之前收藏的一篇老外的文章整理翻译了一下,供大家讨论,如有错误,请大家指出,多谢. ...
- 打包.NET Core的程序到一个单独的可执行文件
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:打包.NET Core的程序到一个单独的可执行文件.
- JavaScript对象 原型
javascript对象就是一组数据和功能的集合,除原始类型(string.number.boolean.null.undefined)之外,其余都是对象. 可以通过对象直接量(字面量).new.和O ...
- log4net写入DB2备忘 via OLEDB & ODBC
在项目中遇到需要记录操作日志的需求,由于是一个外挂系统,因此不用考虑到公司框架的限制,直接二层架构直连数据库,考虑使用log4net连接DB2.请宽恕我这个非软工科班出身的IT小白,以前一直在知道有个 ...
- Spring定时器——时间设置规则
平时经常有一些写Spring定时器的需求,但是每次要设置定时器的时间的时候,老是既不住,到处找别人的博客又各种不爽,所以就自己记录一份吧,顺便整理一下. org.springframework.sch ...