本文章由 WyOJ Shojo 从洛谷专栏拉取,原发布时间为 2021-04-28 16:14:09
思路
定义一个队列 $s$,之后每次输入都进队列中。输入完循环只要队列 $s$ 里面不是只有一个元素,就用 $p1$ 和 $p2$ 代表开头的两个数,之后按照题意插入就可以了。
最后献上我的代码:
#include <iostream>
#include <queue>
#include <cstdlib>
using namespace std;
int main(){
queue<int> s;
int n;
cin>>n;
for(int i=1;i<=1<<n;++i){
int t;
cin>>t;
s.push(t);
}
while(s.size()!=1){
int p1=s.front();
s.pop();
int p2=s.front();
s.pop();
if(p1>p2)
s.push(p1-p2);
if(p1==p2)
s.push(p1);
if(p1<p2)
s.push(p2-p1);
}
cout<<s.front();
return 0;
}

鲁ICP备2025150228号