牛客多校对抗第6场 A Singing Contest
【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.
输入
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的更多相关文章
- 牛客多校训练第八场C.CDMA(思维+构造)
题目传送门 题意: 输入整数m( m∈2k ∣ k=1,2,⋯,10),构造一个由1和-1组成的m×m矩阵,要求对于任意两个不同的行的内积为0. 题解: Code: #include<bits/ ...
- 牛客多校训练第八场G.Gemstones(栈模拟)
题目传送门 题意: 输入一段字符串,字符串中连续的三个相同的字符可以消去,消去后剩下的左右两段字符串拼接,求最多可消去次数. 输入:ATCCCTTG 输出:2 ATCCCTTG(消去CCC)——& ...
- 2019牛客多校训练第四场K.number(思维)
题目传送门 题意: 输入一个只包含数字的字符串,求出是300的倍数的子串的个数(不同位置的0.00.000等都算,并考虑前导零的情况). sample input: 600 1230003210132 ...
- 2019牛客多校训练第三场H.Magic Line(思维)
题目传送门 大致题意: 输入测试用例个数T,输入点的个数n(n为偶数),再分别输入n个不同的点的坐标,要求输出四个整数x1,y1,x2,y2,表示有一条经过点(x1,y1),(x2,y2)的直线将该二 ...
- 2019牛客多校训练第三场B.Crazy Binary String(思维+前缀和)
题目传送门 大致题意: 输入整数n(1<=n<=100000),再输入由n个0或1组成的字符串,求该字符串中满足1和0个数相等的最长子串.子序列. sample input: 801001 ...
- 2019暑假牛客多校训练-第八场-C-CDMA(递归、水题)
观察前3组可以推出递归规律,生成下一个类型时,每行copy自身与自身相反. 题目描述 Gromah and LZR have entered the third level. There is a b ...
- 2018年牛客多校寒假 第四场 F (call to your teacher) (图的连通性)
题目链接 传送门:https://ac.nowcoder.com/acm/contest/76/F 思路: 题目的意思就是判断图的连通性可以用可达性矩阵来求,至于图的存储可以用邻接矩阵来储存,求出来可 ...
- 左闭右开线段树 2019牛客多校(第七场)E_Find the median(点代表区间
目录 题意 一种解析 AC_Code @(2019第七场牛客 E_Find the median 左闭右开线段树) 题意 链接:here 我理解的题意就是:初始序列为空,有\(n(400000)\)次 ...
- 2019牛客多校(第十场)F Popping Balloons —— 线段树+枚举
https://ac.nowcoder.com/acm/contest/890/F 题意:二维平面中有n个气球,你可以横着社三法子弹,竖着射三发子弹,且横着子弹的关系是y,y+r,y+2*r,竖着是x ...
随机推荐
- 51定时器控制4各led,使用回调函数机制
程序转载自51hei,经过自己的实际验证,多了一种编程的思路技能,回调函数的基本思想也是基于事件机制的,哪个事件来了, 就执行哪个事件. 程序中,最多四个子定时器,说明51的处理速度是不够的,在中断中 ...
- C语言实例解析精粹学习笔记——30
实例30: 用已知字符串s中的字符,生成由其中n个字符组成的所有字符排列.设n小于字符串s的字符个数,其中s中的字符在每个排列中最多出现一次.例如,对于s[]="abc",n=2, ...
- win7 下安装oracle 11g出现错误: 启动服务出现错误 找不到服务OracleMTSRecoveryService
这种错误是在多次安装oracle都没有成功的情况下发生的. 正确安装oracle,是有前提条件的 1,安装最新的jdk,不是jre!!(并配好环境变量,在cmd中测试 java -version与ja ...
- python2.7练习小例子(十五)
15):题目:输出指定格式的日期. 程序分析:使用 datetime 模块. 程序源代码: #!/usr/bin/python # -*- coding: UTF-8 -*- ...
- Django的命令操作,python
忘记时候,查看命令用:python manage.py 1 建立项目的命令: django-admin.py startproject project_name 2 在项目的目录下建立app: dja ...
- jenkins 构建部署时tomcat7 内存溢出解决方案
在使用jenkins构建部署时一直出现tomcat7内存溢出 WARNING: Unexpected node monitoring termination: Clock Difference jav ...
- Java - 问题集 - 导出csv文件中文乱码
微软的excel文件需要通过文件头的bom来识别编码,所以写文件时,需要先写入bom头. FileOutputStream fos = new FileOutputStream(new File(&q ...
- 源码-集合:ArrayList
只是文章摘录,还未研究 JAVA ArrayList详细介绍(示例) http://www.jb51.net/article/42764.htm Jdk1.6 JUC源码解析汇总 - 永远保持敬畏之心 ...
- LuffyCity-CMDB实战
第1章 章节一 课时01-ITIL介绍 课时02-CMDB介绍 课时03-CMDB需求讨论 课时04-CMDB需求讨论2 课时05-CMDB表结构设计 课时06-CMDB表结构设计2 课时07-CMD ...
- Leetcode 3. Longest Substring Without Repeating Characters (Medium)
Description Given a string, find the length of the longest substring without repeating characters. E ...