【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()+);
}
}

最新文章

  1. libvirt 网络手册(一)
  2. Java 体系结构
  3. MSDN资料
  4. 建站服务器的最优选择之Windows Or Linux
  5. 小结css2与css3的区别
  6. ArcGIS导出辖区边界点坐标
  7. Yii2快速总结
  8. 工作笔记6-java相关
  9. Centos 7下下载和安装docker
  10. 模拟js中注册表单验证
  11. react native的注释
  12. go语言练习:通道、协程
  13. MongoDB索引,性能分析
  14. Matlab图形调色
  15. JAVA基础知识详解
  16. dp_c_区间dp_g
  17. Markdown - 让网络书写变得简单
  18. Jmeter 重要测试指标释义
  19. C# 正则表达式替换换行
  20. 简述web工程师的职责与学习

热门文章

  1. 数字滤波器的MATLAB与FPGA实现--Altera/Verilog版的pdf版,杜勇等编著的书。
  2. Spring 中的文件上传与下载控制
  3. python基础之反射、面向对象进阶
  4. 15 GIL 全局解释器锁 C语言解决 top ps
  5. MyEclipse - 问题集 - 创建Maven项目,JDK版本默认是1.5
  6. 三种block
  7. c++返回引用
  8. 把python脚本打包成win可执行文件
  9. python3.x 编码问题
  10. python学习总结----内置函数及数据持久化