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 ...
随机推荐
- idea软件操作
1.快捷键: 1.1.格式化代码:crtl+alt+L 1.2.一些构造啊,setter/getter等方法:alt+insert 1.3.crtl + f 搜素当前页面
- 项目部署到tomcat,验证部署成功
1.假设你已经知道打war包放上去了tomcat 下的webapps下 2. bin->启动startup.bat 3.浏览器中启动 http://ip:port 这个port是tomca ...
- HBuilderX开发app实现自动更新版本
需求说明:使用MUI+Vue等技术并且通过HBuilderX打包开发移动app,在有版本更新时需要自动提示用户有新版本,并且可以点击下载自动安装. 思路说明: 应用打开时(使用Vue的生命周期mo ...
- phpstorm实用技巧
1.切换php代码版本提示 1.1找到External Libraries右键点击(configure PHP Include Paths) 1.2切换提示版本(在这里切换版本)确定即可 2.生成ge ...
- 高效完成R代码
为什么R有时候运行慢? 参考https://www.cnblogs.com/qiaoyihang/p/7779144.html 一.为什么R程序有时候会很慢? 1.计算性能的三个限制条件 cpu ra ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A Math Problem
//只要从所有区间右端点的最小值覆盖到所有区间左端点的最大值即可 #include<iostream> using namespace std ; int x,y; int n; int ...
- MySQL | linux中数据库导出和导入
一.数据库导出(深坑) 命令:mysqldump -u用户名 -p密码 要导出的数据库 > 导出之后的文件.sql mysqldump -uroot -p database_01 > da ...
- String Buffer和String Builder(String类深入理解)
String在Java里面JDK1.8后它属于一个特殊的类,在创建一个String基本对象的时候,String会向“ 字符串常量池(String constant pool)” 进行检索是否有该数 ...
- [CF]Round513
A Phone Numbers 题意:定义"电话号码"为开头为'8',长度为11的字符串.给定一些字符,每个字符只能用一次,求可以拼出多少个电话号码(可以重复). 直接min(st ...
- 用python制作多份试卷防止作弊(随机排列题目顺序和答案顺序,提供参考答案)
#! /usr/bin/python# randomQuizeGenerator.py - Creates quizzes with questions and answers in # ra ...