【20分】标题: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 i-th 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号pk,3号和4号pk,。。。and so on,每个歌手已经知道对方每首的愉悦值,愉悦值大的歌会淘汰愉悦值小的歌,求哪位歌手最终可以获胜
题解:每首歌用了后就不能用,但是要打败目前的对手,那么我们将歌的愉悦值排序,谁最大的愉悦值小谁就out了,但是愉悦值大的歌手不能浪费他最大愉悦值的那首歌,找到尽可能小的获胜歌手的一首歌去out掉他的对手就行,把愉悦值大的尽可能留到后面 代码如下:
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 2e4+;
int n;
queue<LL> q;
vector<LL> v[maxn];
void init(){
for(int i=;i<maxn;i++){
v[i].clear();
}
while(!q.empty()){
q.pop();
} }
bool cmp(long long a,long long b){
return a>b;
}
int main(){
#ifndef ONLINE_JUDGE
FIN
#endif
int T;
scanf("%d",&T);
int cas=;
while(T--){
init();
scanf("%d",&n);
int m=pow(,n);
for(int i=;i<m;i++){
for(int j=;j<n;j++){
LL t;
scanf("%lld",&t);
v[i].push_back(t);
}
sort(v[i].begin(), v[i].end(),cmp);
q.push(i);
}
printf("Case #%d: ",cas++);
while(q.size()>){
int t1,t2;
t1=q.front();q.pop();
t2=q.front();q.pop();
if(v[t1][]<v[t2][]){
swap(t1,t2);
}
q.push(t1);
vector<LL>::iterator it;
int i=;
for(it=v[t1].begin();it!=v[t1].end();it++){
if(i==n-){
v[t1].erase(v[t1].begin()+i);
break;
}
if(v[t1][i]>v[t2][]&&v[t1][i+]<v[t2][]){
v[t1].erase(v[t1].begin()+i);
break;
}
i++;
} }
printf("%d\n",q.front()+);
}
}

牛客多校对抗第6场 A Singing Contest的更多相关文章

  1. 牛客多校训练第八场C.CDMA(思维+构造)

    题目传送门 题意: 输入整数m( m∈2k ∣ k=1,2,⋯,10),构造一个由1和-1组成的m×m矩阵,要求对于任意两个不同的行的内积为0. 题解: Code: #include<bits/ ...

  2. 牛客多校训练第八场G.Gemstones(栈模拟)

    题目传送门 题意: 输入一段字符串,字符串中连续的三个相同的字符可以消去,消去后剩下的左右两段字符串拼接,求最多可消去次数. 输入:ATCCCTTG   输出:2 ATCCCTTG(消去CCC)——& ...

  3. 2019牛客多校训练第四场K.number(思维)

    题目传送门 题意: 输入一个只包含数字的字符串,求出是300的倍数的子串的个数(不同位置的0.00.000等都算,并考虑前导零的情况). sample input: 600 1230003210132 ...

  4. 2019牛客多校训练第三场H.Magic Line(思维)

    题目传送门 大致题意: 输入测试用例个数T,输入点的个数n(n为偶数),再分别输入n个不同的点的坐标,要求输出四个整数x1,y1,x2,y2,表示有一条经过点(x1,y1),(x2,y2)的直线将该二 ...

  5. 2019牛客多校训练第三场B.Crazy Binary String(思维+前缀和)

    题目传送门 大致题意: 输入整数n(1<=n<=100000),再输入由n个0或1组成的字符串,求该字符串中满足1和0个数相等的最长子串.子序列. sample input: 801001 ...

  6. 2019暑假牛客多校训练-第八场-C-CDMA(递归、水题)

    观察前3组可以推出递归规律,生成下一个类型时,每行copy自身与自身相反. 题目描述 Gromah and LZR have entered the third level. There is a b ...

  7. 2018年牛客多校寒假 第四场 F (call to your teacher) (图的连通性)

    题目链接 传送门:https://ac.nowcoder.com/acm/contest/76/F 思路: 题目的意思就是判断图的连通性可以用可达性矩阵来求,至于图的存储可以用邻接矩阵来储存,求出来可 ...

  8. 左闭右开线段树 2019牛客多校(第七场)E_Find the median(点代表区间

    目录 题意 一种解析 AC_Code @(2019第七场牛客 E_Find the median 左闭右开线段树) 题意 链接:here 我理解的题意就是:初始序列为空,有\(n(400000)\)次 ...

  9. 2019牛客多校(第十场)F Popping Balloons —— 线段树+枚举

    https://ac.nowcoder.com/acm/contest/890/F 题意:二维平面中有n个气球,你可以横着社三法子弹,竖着射三发子弹,且横着子弹的关系是y,y+r,y+2*r,竖着是x ...

随机推荐

  1. asp.net core mvc简介

    MVC 通常而言,我们使用.NET Core MVC 构建网页应用与 API,MVC是使用模型-视图-控制器(Model-View-Controller)设计模式. 创建项目 使用如下命令创建一个名称 ...

  2. vue2.0 Axios 的简单用法

    安装 使用 npm: $ npm install axios 使用 bower: $ bower install axios 使用 cdn: <script src="https:// ...

  3. DDR分析与布线要求

    基本知识 Double Data Rate Synchronous Dynamic Random Access Memory 简称 DDR SDRAM 双倍数据率同步动态随机存取内存 DDR SDRA ...

  4. 区分Oracle的数据库,实例,服务名,SID

    文章摘自:http://www.zhetao.com/content240 感谢分享O(∩_∩)O~ 在实际的开发应用中,关于Oracle数据库,经常听见有人说建立一个数据库,建立一个Instance ...

  5. 转MySQL详解--索引

    写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将 ...

  6. Delphi实例之橡皮筋画图的实现

    Delphi实例之橡皮筋画图的实现 在<Delphi7基础教程>这本书的练习中提到过一个橡皮筋画图的例子,书上的源码是错误的!不知道是打印的错误还是本身源码就有问题,我将它改了过来. 在F ...

  7. 关闭 Identity 插入限制

    当为identity列插入时会报错: 仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'xx'中的标识列指定显式值. 但在复制表数据时想带主键一起复制时,这时要设置IDEN ...

  8. 你可能会用到的"奇技赢巧"

    工作中偶尔会遇到一些不常见的问题,但是解决起来又极其麻烦,通常要找很多资料才能搞定,这里我总结了近段时间遇到的一些问题,可能会对你有帮助,高手勿喷. 1.关于iPhone最下面会弹出奇怪框框的问题 就 ...

  9. Web框架本质及浅谈HTTP协议

    Web框架本质 我们可以这样理解:所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端. 这样我们就可以自己实现Web框架了. 半成品自定义web框架 impor ...

  10. git部署详解

    1.1 关于版本控制 1.1.1 本地版本控制 本地版本控制系统 许多人习惯用复制整个项目目录的方式来保存不同的版本,或许还会改名加上备份时间以示区别.这么做唯一的 好处就是简单,但是特别容易犯错.有 ...