题目链接: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 【模拟】的更多相关文章

  1. 牛客多校第六场 A Garbage 模拟/签到

    题意: 给你一个字符串,代表一个垃圾都有哪些物质组成,再给你一个字符串,代表a-z代表的物质分别是有害物质,干物质还是湿物质,根据题目的定义,回答是什么垃圾. 题解: 根据题意模拟即可. #inclu ...

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

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

  3. 牛客多校对抗第6场 A Singing Contest

    [20分]标题:A.Singing Contest | 时间限制:1秒 | 内存限制:256MJigglypuff is holding a singing contest. There are 2n ...

  4. 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard

    山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...

  5. noi.ac 第五场第六场

    t1应该比较水所以我都没看 感觉从思路上来说都不难(比牛客网这可简单多了吧) 第五场 t2: 比较套路的dp f[i]表示考虑前i个数,第i个满足f[i]=i的最大个数 i能从j转移需要满足 j< ...

  6. 2014 HDU多校弟六场J题 【模拟斗地主】

    这是一道5Y的题目 有坑的地方我已在代码中注释好了 QAQ Ps:模拟题还是练的太少了,速度不够快诶 //#pragma comment(linker, "/STACK:16777216&q ...

  7. Gym.101908 Brazil Subregional Programming Contest(寒假自训第六场)

    这几天睡眠时间都不太够,室友晚上太会折腾了,感觉有点累,所以昨天的题解也没写,看晚上能不能补起来. B . Marbles 题意:给定N组数(xi,yi),玩家轮流操作,每次玩家可以选择其中一组对其操 ...

  8. 多校第六场 HDU 4927 JAVA大数类+模拟

    HDU 4927 −ai,直到序列长度为1.输出最后的数. 思路:这题实在是太晕了,比赛的时候搞了四个小时,从T到WA,唉--对算组合还是不太了解啊.如今对组合算比較什么了-- import java ...

  9. 2019牛客多校第六场 B - Shorten IPv6 Address 模拟

    B - Shorten IPv6 Address 题意 给你\(128\)位的二进制,转换为十六进制. 每\(4\)位十六进制分为\(1\)组,每两组用一个\(":"\)分开. 每 ...

随机推荐

  1. (转)浅谈千万级PV/IP规模高性能高并发网站架构

    浅谈千万级PV/IP规模高性能高并发网站架构 原文:http://blog.51cto.com/oldboy/736710 文章架构简图:   高并发访问的核心原则其实就一句话“把所有的用户访问请求都 ...

  2. sqlplus连接oracle语法

    sqlplus文件在product\11.2.0\dbhome_1\BIN目录下. 连接语法:用户名/密码@ip/服务名

  3. Unity3D游戏轻量级xlua热修复框架

    Unity3D游戏轻量级xlua热修复框架   一 这是什么东西 前阵子刚刚集成xlua到项目,目的只有一个:对线上游戏C#逻辑有Bug的地方执行修复,通过考察xlua和tolua,最终选择了xlua ...

  4. Understanding Java 8 Streams API---reference

    http://java.amitph.com/2014/01/understanding-java-8-streams-api.html Since past few versions, Java h ...

  5. [转] .net core Session , Working with a distributed cache

    本文转自:https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed By Steve Smith+ Di ...

  6. module.exports和 exports 方法暴露

    在Node.js包管理时需要把方法暴露给外部文件 文件:Hello.js    Hello方法是模仿面向对象类的写法 function Hello() { var name; this.setName ...

  7. Quartz使用及注意事项

    Quartz使用及注意事项 前提:目前由于公司业务决定,大量使用Quartz,每天固定的时间点执行相应的业务逻辑,,几十个时间点应该是有的,某一个时间点如果没有执行带来的问题是巨大的.Quartz的稳 ...

  8. Csharp:TinyMCE HTML Editor in .NET WindowsForms

    /// <summary> /// /// </summary> public partial class Form2 : Form { private mshtml.IHTM ...

  9. 常用css属性记录

    CSS常用属性: 字体属性:(font)大小 font-size: x-large;(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD样式 font-style: ...

  10. CKRule业务规则管理系统部署说明

    1.   程序包说明 软件是使用WinForm开发的,包含服务端和客户端,服务端部署在IIS上面,客户端可以在已经安装.Net4.0的windows上面运行. 1.1.  服务端程序包 CKBrmsS ...