![](https://img2020.cnblogs.com/blog/1892543/202101/1892543-20210116135841128-1830761252.png)
- 题意:有(2^n)个人站成一排比赛,刚开始每个人都和自己右边的人进行比赛,赢得人晋级下一轮(下标的小的在前面),不断重复这个过程,问最后拿到第二名的人的编号.
- 题解:根据题意,可以用vector直接模拟这个过程.
- 代码:
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
n=pow(2,n);
vector<int> a(n);
vector<int> v;
for(auto &w:a) cin>>w;
if(n==2){
if(a[0]>a[1]) cout<<2<<'
';
else cout<<1<<'
';
return 0;
}
rep(i,0,n-1){
if(i&1){
if(a[i]>=a[i-1]) v.pb(i);
else v.pb(i-1);
}
}
while(v.size()>2){
vector<int> tmp=v;
v.clear();
for(int i=0;i<(int)tmp.size();++i){
if(i&1){
if(a[tmp[i]]>a[tmp[i-1]]) v.pb(tmp[i]);
else v.pb(tmp[i-1]);
}
}
}
if(a[v[0]]>a[v[1]]) cout<<v[1]+1<<'
';
else cout<<v[0]+1<<'
';
return 0;
}