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

最新文章

  1. iOS - XIB之AutoLayout添加约束
  2. 动态调用webservice(部分转载)
  3. Linux (Centos)操作MySql命令
  4. [ZZ] Adventures with Gamma-Correct Rendering
  5. Android根据baidu Android定位SDK实现定位
  6. P3383: [Usaco2004 Open]Cave Cows 4 洞穴里的牛之四
  7. Yii 显示错误信息(Fatal Error,Warning)在页面上
  8. Highcharts接收后台传来的json对象值无法显示
  9. ubuntu cenots 禁止本地登陆
  10. node.js(五)字符串转换
  11. Overload和Override的区别。Overloaded的方法是否可以改变返回值的类型?
  12. 常用表单验证&amp;&amp;常用正则
  13. Javascript高级编程学习笔记(18)—— 引用类型(7)单体内置对象
  14. docker --环境变量制作模板
  15. VMware5.5-添加数据中心,集群及主机
  16. Mac使用Xcode配置openGL
  17. Redis基本管理
  18. 判断元素16种方法expected_conditions
  19. [转]php curl 设置host curl_setopt CURLOPT_HTTPHEADER 指定host
  20. linux磁盘清理记录

热门文章

  1. 解决matplotlib绘图中文乱码
  2. 数据库~大叔通过脚本生成poco实体
  3. Springboot - 自定义错误页面
  4. win7 docker的受难记——exit status 255的终极解决
  5. 2、按钮:Buttons
  6. Angular6路由复用与延迟加载的冲突解决——看看有备无患
  7. Java 的版本历史与特性
  8. 标准c库函数和linux系统函数的关系
  9. Bootstrap拟态框+支付宝首页
  10. SharePoint 2013 - Add-ins