You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 260;
|
|
|
|
|
|
|
|
|
|
struct node {
|
|
|
|
|
int value;
|
|
|
|
|
int winner;
|
|
|
|
|
} nodes[N];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//本题n的概念很奇葩,不是n个国家,是2^n个国家~,比如n=3,就是2^3个国家,即8个国家。
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
//函数定义:计算x结点的获胜者
|
|
|
|
|
void dfs(int x) {
|
|
|
|
|
//叶子结点
|
|
|
|
|
if (x >= (1 << n)) return;
|
|
|
|
|
//左子树,右子树
|
|
|
|
|
dfs(2 * x), dfs(2 * x + 1);
|
|
|
|
|
//左结点值,右结点值
|
|
|
|
|
int lvalue = nodes[2 * x].value, rvalue = nodes[2 * x + 1].value;
|
|
|
|
|
//pk
|
|
|
|
|
if (lvalue > rvalue) nodes[x].value = lvalue, nodes[x].winner = nodes[2 * x].winner;
|
|
|
|
|
else nodes[x].value = rvalue, nodes[x].winner = nodes[2 * x + 1].winner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
测试用例:
|
|
|
|
|
3
|
|
|
|
|
4 2 3 1 10 5 9 7
|
|
|
|
|
*/
|
|
|
|
|
int main() {
|
|
|
|
|
cin >> n;
|
|
|
|
|
for (int i = 0; i < (1 << n); i++) {//完美二叉树结点个数 2^n-1
|
|
|
|
|
int k = i + (1 << n);
|
|
|
|
|
cin >> nodes[k].value; //读入各个结点的能力值
|
|
|
|
|
nodes[k].winner = i + 1; //叶子结点的获胜方就是自己国家的编号
|
|
|
|
|
}
|
|
|
|
|
dfs(1);//从根结点开始遍历
|
|
|
|
|
//找亚军
|
|
|
|
|
cout << ((nodes[2].value > nodes[3].value) ? nodes[3].winner : nodes[2].winner) << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|