-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASingingContest.cpp
52 lines (50 loc) · 1.18 KB
/
ASingingContest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
struct node{
int a[15];
int id;
};
int main(){
int _;
scanf("%d",&_);
int zz=1;
while(_--){
queue<node >qu;
int n;
scanf("%d",&n);
node x;
for (int k = 1; k <=1<<n ; ++k) {
for (int i = 0; i <n ; ++i) {
scanf("%d,",&x.a[i]);
}
x.id=k;
sort(x.a,x.a+n);
qu.push(x);
}
node u,v;
while (!qu.empty()){
if(qu.size()==1)
break;
u=qu.front();
qu.pop();
v=qu.front();
qu.pop();
if(u.a[n-1]>v.a[n-1]){
int k=upper_bound(u.a,u.a+n,v.a[n-1])-u.a;
u.a[k]=0;
sort(u.a,u.a+n);
qu.push(u);
}
else{
int k=upper_bound(v.a,v.a+n,u.a[n-1])-v.a;
v.a[k]=0;
sort(v.a,v.a+n);
qu.push(v);
}
}
v=qu.front();
printf("Case #%d: %d\n",zz++,v.id);
}
return 0;
}