#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. linux - redis-trib.rb 命令详解

    参考网站 http://www.cnblogs.com/ivictor/p/9768010.html 简介 redis-trib.rb是官方提供的Redis Cluster的管理工具,无需额外下载,默 ...

  2. navicat异常 - 1130-host ... is not allowed to connect to this MySql server

    错误描述 用navicat连接数据库报错:1130-host ... is not allowed to connect to this MySql server如何处理 解决方案 1.连接服务器: ...

  3. Spring Boot2 快速入门教程-到上手

    Spring Boot2 教程合集 入门 纯 Java 代码搭建 SSM 环境 创建一个 Spring Boot 项目的三种方法 理解 Spring Boot 项目中的 parent 基础配置 配置文 ...

  4. 项目转移时发生的错误<springboot+mybatis(xml逆向工程自动生成)>

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'app ...

  5. java注册界面及mysql连接

    题目要求 完成注册界面及添加功能 1登录账号:要求由6到12位字母.数字.下划线组成,只有字母可以开头:(1分) 2登录密码:要求显示“• ”或“*”表示输入位数,密码要求八位以上字母.数字组成.(1 ...

  6. ORA-00928: missing SELECT keyword

    问题描述 ORA-00928: missing SELECT keyword 问题原因 未写表名

  7. <img src = "..."/>的一个图片上面怎么在放上字

    转自:https://zhidao.baidu.com/question/1495805873400412779.html 例子1: html中可以用css相对定位让文字在图片的上面. 1.新建htm ...

  8. python3.0练习100题——001

    自学python3中,现在开始每天在python2.71 100例中做一道题,用python3实现,并写下一些思考-加油(ง •̀灬•́)ง 题目网站(http://www.runoob.com/py ...

  9. 工具系列 | git checkout 可替换命令 git switch 和 git restore

    前言 git checkout 这个命令承担了太多职责,既被用来切换分支,又被用来恢复工作区文件,对用户造成了很大的认知负担. Git社区发布了Git的新版本2.23.在该版本中,有一个特性非常引人瞩 ...

  10. win10下安装es

    1.安装前提 windows下已经安装好了jdk8的版本 2.下载ElasticSearch https://www.elastic.co/cn/downloads/elasticsearch#ga- ...