2019冬季PAT甲级第四题
#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甲级第四题的更多相关文章
- 2019冬季PAT甲级第三题
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; ]; int main(){ ...
- 2019冬季PAT甲级第二题
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; typedef struct{ int ...
- 2019冬季PAT甲级第一题
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ][]; ][]; ]; string ...
- 2019秋季PAT甲级_备考总结
2019 秋季 PAT 甲级 备考总结 在 2019/9/8 的 PAT 甲级考试中拿到了满分,考试题目的C++题解记录在这里,此处对备考过程和考试情况做一个总结.如果我的方法能帮助到碰巧点进来的有缘 ...
- PAT甲级训练刷题代码记录
刷题链接:https://www.patest.cn/contests/pat-a-practise 1001 #include <iostream> #include <stdio ...
- 2019秋季PAT甲级_C++题解
2019 秋季 PAT (Advanced Level) C++题解 考试拿到了满分但受考场状态和知识水平所限可能方法不够简洁,此处保留记录,仍需多加学习.备考总结(笔记目录)在这里 7-1 Fore ...
- PAT甲级 二叉树 相关题_C++题解
二叉树 PAT (Advanced Level) Practice 二叉树 相关题 目录 <算法笔记> 重点摘要 1020 Tree Traversals (25) 1086 Tree T ...
- PAT甲级 Dijkstra 相关题_C++题解
Dijkstra PAT (Advanced Level) Practice Dijkstra 相关题 目录 <算法笔记>重点摘要 1003 Emergency (25) <算法笔记 ...
- PAT甲级 散列题_C++题解
散列 PAT (Advanced Level) Practice 散列题 目录 <算法笔记> 重点摘要 1002 A+B for Polynomials (25) 1009 Product ...
随机推荐
- .net Core 安装在linux上
1.安装 .net Core 参考官方网站 https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install 2.发布应用程 ...
- python3练习100题——034
题目:练习函数调用. 这个很容易了. def hello_world(): return "hello, world!" def fun(): print(hello_world( ...
- for循环与闭包
Es5 function box(){ var arr = []; ;i<;i++){ arr[i] = (function(num){ //自我执行,并传参(将匿名函数形成一个表达式)(传递一 ...
- Python之二:基础知识
1.常量: 1.1.数:5.1.23.9.25e-3 4种类型的数——整数.长整数.浮点数和复数 2是一个整数的例子. 长整数不过是大一些的整数. 3.23和52.3E-4是浮点数的例子.E标记表示1 ...
- HTML表格显示的笔记
有时需要显示的复杂表头 如图所示 <table id="" cellpadding="0" cellspacing="0" bord ...
- CI系列之配置sonar
基于GO项目 1.在jenkins新建sonar任务,设置2个变量用于接收代码分支和pipline的workspace[两个变量的作用在CI之Jenkinsfile中会讲到] A.添加构建参数 B.选 ...
- Android开发之JDK配置,及ADT下载
第一步: 到官网上下载jdk,记住关键的一点,首先要查看自己的windows电脑是32位的还是64位的,这里想下载相应的位数的jdk 第二步: 安装JDK,一般默认安装路径,不做自己修改安装路径,如: ...
- 洛谷P1147 连续自然数和
https://www.luogu.org/problem/P1147 #include<bits/stdc++.h> using namespace std; int main(){ i ...
- RFC3984: RTP Payload Format for H.264 Video(中文版)
转载地址:https://blog.csdn.net/h514434485/article/details/51010950 官方文档,中文版本地址:http://www.rosoo.net/File ...
- 【STM32H7教程】第60章 STM32H7的DAC应用之定时器触发实现DMA方式双通道波形
完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第60章 STM32H7的DAC应用之定时器触发实 ...