(第六场)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\)组,每两组用一个\(":"\)分开. 每 ...
随机推荐
- mapper mysl实现批量插入 更新
1.批量插入 <insert id="insertConfirm" parameterType="java.util.List"> insert i ...
- Java for循环的几种用法分析
J2SE 1.5提供了另一种形式的for循环.借助这种形式的for循环,可以用更简单地方式来遍历数组和Collection等类型的对象.本文介绍使用这种循环的具体方式,说明如何自行定义能被这样遍历的类 ...
- 常用sql语句整理[MySql]
查看执行计划 explain update test100 set contractSn=99 where contractSn=45; insert ... on duplicate key使用 i ...
- 0.数据结构(python语言) 基本概念 算法的代价及度量!!!
先看思维导图: *思维导图有点简陋,本着循循渐进的思想,这小节的知识大多只做了解即可. *重点在于算法的代价及度量!!!查找资料务必弄清楚. 零.四个基本概念 问题:一个具体的需求 问题实例:针对问题 ...
- js 中移动元素的方法
2017-12-13 19:59:24 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- Flask 框架理解(一)
Flask 框架理解(一) web 服务器 , web 框架 以及 WSGI 这里说的 web 服务器特指纯粹的 python HTTP 服务器(比如 Gunicorn,而不是 Apache,Ngin ...
- sqlserver 限制用户只能访问指定的视图
项目中有一个需求,要求给其它单位提供数据,我们用到了视图,并要求不能让他们看到数据库中的其它数据,我们为其创建了单独的账号,并只能看到指定视图 一.创建视图 CREATE VIEW [dbo].[v_ ...
- [转]mvc5+ef6+Bootstrap 项目心得--身份验证和权限管理
本文转自:http://www.cnblogs.com/shootingstar/p/5629668.html 1.mvc5+ef6+Bootstrap 项目心得--创立之初 2.mvc5+ef6+B ...
- SQL Server Profiler(转载)
SQL Server Profiler工具 一.SQL Profiler工具简介 SQL Profiler是一个图形界面和一组系统存储过程,其作用如下: 图形化监视SQL Server查询: 在后台收 ...
- JavaScript对象 创建对象(二)
组合使用构造函数和原型模式创建对象 function Person(name, age, job){ this.name = name; this.age = age; this.job = job; ...