#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int data;
node *lchild,*rchild;
}tree;
int a[];
tree *build(int l,int r){
if(l>r)
return NULL;
int mn=1e9+,pos=;
for(int i=l;i<=r;++i)
if(a[i]<mn)
mn=a[i],pos=i;
tree *temp=new tree();
temp->data=mn;
temp->lchild=build(l,pos-);
temp->rchild=build(pos+,r);
return temp;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i)
cin>>a[i];
tree *temp=build(,n);
queue<tree *>q;
q.push(temp);
int ans[]={};
int cnt=;
while(!q.empty()){
tree *now=q.front();
q.pop();
ans[++cnt]=now->data;
if(now->lchild)
q.push(now->lchild);
if(now->rchild)
q.push(now->rchild);
}
for(int i=;i<=cnt;++i){
if(i>)
cout<<" ";
cout<<ans[i];
}
return ;
}

2019冬季PAT甲级第四题的更多相关文章

  1. 2019冬季PAT甲级第三题

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; ]; int main(){ ...

  2. 2019冬季PAT甲级第二题

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; typedef struct{ int ...

  3. 2019冬季PAT甲级第一题

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ][]; ][]; ]; string ...

  4. 2019秋季PAT甲级_备考总结

    2019 秋季 PAT 甲级 备考总结 在 2019/9/8 的 PAT 甲级考试中拿到了满分,考试题目的C++题解记录在这里,此处对备考过程和考试情况做一个总结.如果我的方法能帮助到碰巧点进来的有缘 ...

  5. PAT甲级训练刷题代码记录

    刷题链接:https://www.patest.cn/contests/pat-a-practise 1001 #include <iostream> #include <stdio ...

  6. 2019秋季PAT甲级_C++题解

    2019 秋季 PAT (Advanced Level) C++题解 考试拿到了满分但受考场状态和知识水平所限可能方法不够简洁,此处保留记录,仍需多加学习.备考总结(笔记目录)在这里 7-1 Fore ...

  7. PAT甲级 二叉树 相关题_C++题解

    二叉树 PAT (Advanced Level) Practice 二叉树 相关题 目录 <算法笔记> 重点摘要 1020 Tree Traversals (25) 1086 Tree T ...

  8. PAT甲级 Dijkstra 相关题_C++题解

    Dijkstra PAT (Advanced Level) Practice Dijkstra 相关题 目录 <算法笔记>重点摘要 1003 Emergency (25) <算法笔记 ...

  9. PAT甲级 散列题_C++题解

    散列 PAT (Advanced Level) Practice 散列题 目录 <算法笔记> 重点摘要 1002 A+B for Polynomials (25) 1009 Product ...

随机推荐

  1. 【C语言】输出半径1到10的圆的面积,当面积值超过100时,停止执行本程序

    #include<stdio.h> #define PI 3.142 int main() { int r; float area; ; r <= ; r++) { area = P ...

  2. 论文阅读笔记(三)【AAAI2017】:Learning Heterogeneous Dictionary Pair with Feature Projection Matrix for Pedestrian Video Retrieval via Single Query Image

    Introduction (1)IVPR问题: 根据一张图片从视频中识别出行人的方法称为 image to video person re-id(IVPR) 应用: ① 通过嫌犯照片,从视频中识别出嫌 ...

  3. Lumen跨域问题,PHP CORS Middleware

    前导 本篇文字作为?<「新轮子」PHP CORS (Cross-origin resource sharing),解决 PHP 项目程序设置跨域需求.>的续篇. 简介 什么是 medz/c ...

  4. promise的连缀写法

    promise的连缀写法 以上写法相当于写了两个实例 promise.all() 1. promise.all() all这个方法是 promise 构造函数的成员不是实例对象成员,这个方法接受一个参 ...

  5. Ubuntu下vsc+python3配置

    我发现直接搜这个很容易得到过时的文章py2请滚蛋好么 1.首先下去VSC官网下载.deb的安装包,安装好vsc,打开后安装PYTHON,reload下.别啊忘记修改路径,setting下搜python ...

  6. Chrome 提标 您的浏览器限制了第三方Cookie...解决方法

    最近升级Chrome后会出现  您的浏览器限制了第三方Cookie,这将影响您正常登录,您可以更改浏览器的隐私设置,解除限制后重试. 解决方法: chrome://flags/ 把这句复制到浏览器回车 ...

  7. eclipse的安装和环境配置

    一,eclipse下载 地址:https://www.eclipse.org/downloads/ 一般浏览器都有翻译功能 二.有32位和64位的版本根据自己的需求下载,选下载的选下载量最多的下载. ...

  8. [P3806] 【模板】点分治 - 点分治

    辣鸡蒟蒻怎么今天才来敲这个模板题 好像还敲了很久的样子 (大雾) #include <bits/stdc++.h> using namespace std; #define int lon ...

  9. energy/heating data source

    HeatManDataLake 1. schema: hfors tables ambient_temperature_emd record the ambient temperature hourl ...

  10. print format

    python基础_格式化输出(%用法和format用法) name = 'jack' age = 18 sex = 'man' job = "IT" salary = 9999.9 ...