求助大佬
#include <bits/stdc++.h>
using namespace std;
int value[260], winner[260], a[260];
int n;
int fid(int b) {
for (int i = 1; i <= (1 << n); i++) {
if (a[i] == b) {
cout << i;
return 0;
}
}
}
void dfs(int x) {
if (x >= 1 << n)
return;
else {
dfs(2 * x);
dfs(2 * x + 1);
int l = value[2 * x], r = value[2 * x + 1];
if (l > r) {
value[x] = l;
winner[x] = winner[2 * x];
} else {
value[x] = r;
winner[x] = winner[2 * x + 1];
}
}
}
int main() {
cin >> n;
for (int i = 1; i < (1 << n); i++) {
cin >> value[i + (1 << n)];
a[i] = value[i + (1 << n)];
winner[i + (1 << n)];
}
dfs(1);
if (value[2] > value[3]) {
fid(value[3]);
} else {
fid(value[2]);
}
return 0;
}