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 ...
随机推荐
- centos 7 源码安装openresty
Openresty 官网 http://openresty.org Openresty源码下载页面 http://openresty.org/en/download.html Openresty 简易 ...
- 关于List比较好玩的操作
作为Java大家庭中的集合类框架,List应该是平时开发中最常用的,可能有这种需求,当集合中的某些元素符合一定条件时,想要删除这个元素.如: public class ListTest { publi ...
- Linux C/C++ 字符串逆序
/*字符串逆序*/ #include <stdio.h> #include <string.h> void nixu(char *str) { ; char tmp; for( ...
- MySQL 8.0.18 在 Windows Server 2019 上的安装(ZIP)公开
AskScuti MySQL : Windows Server 2019 安装 MySQL 8.0 温馨提示:为了展现我最“魅力”的一面,请用谷歌浏览器撩我. 一切就绪,点我开撩
- Django学习笔记4
Referto https://docs.djangoproject.com/zh-hans/2.2/intro/tutorial04/ Since we have the abstract conc ...
- OpenGL 编程指南 (2)
1.OpenGL对共享的边有严格的规定:1)共享边上的像素因为同事被两者所覆盖,因此不可能不受到光照计算的影响: 2)共享边上的像素值,不可能受到多于一个三角形的光照计算的影响. 2.多边形存在正面与 ...
- 题解【洛谷P2070】刷墙
题面 将每一次移动的距离进行差分,前缀和判断移动的距离是否\(\geq 2\)即可. #include <bits/stdc++.h> #define itn int #define gI ...
- 题解 【洛谷P1332】血色先锋队
题面:https://www.luogu.org/problemnew/show/P1332 很容易看出,这是一个典型的广度优先搜索,也就是众多OIer口中的bfs. 先给各位普及一下bfs(部分来自 ...
- Illegal target for the requested operation
org.tigris.subversion.javahl.ClientException: Illegal target for the requested operation svn: Commit ...
- UES
Spring-core-4.3.16 ObjectUtils.java public static boolean isEmpty(Object obj) { if (obj == null) { r ...