PAT (Advanced Level) 1064. Complete Binary Search Tree (30)
因为是要构造完全二叉树,所以树的形状已经确定了。
因此只要递归确定每个节点是多少即可。
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<queue>
- #include<vector>
- #include<string>
- #include<stack>
- #include<map>
- #include<algorithm>
- using namespace std;
- int a[+],ans[+];
- int f[+],sz[+];
- int n;
- void t(int id)
- {
- if(*id>n&&*id+>n)
- {
- f[id]=; sz[id]=; return;
- }
- if(*id<=n) t(*id);
- if(*id+<=n) t(*id+);
- f[id]=sz[*id];
- sz[id]=sz[*id]+sz[*id+]+;
- }
- void dfs(int id,int L,int R)
- {
- ans[id]=a[L+f[id]];
- if(*id<=n) dfs(*id,L,L+f[id]-);
- if(*id+<=n) dfs(*id+,L+f[id]+,R);
- }
- int main()
- {
- scanf("%d",&n);
- for(int i=;i<=n;i++) scanf("%d",&a[i]);
- sort(a+,a++n);
- memset(f,,sizeof f);
- memset(sz,,sizeof sz);
- t();
- dfs(,,n);
- for(int i=;i<=n;i++)
- {
- printf("%d",ans[i]);
- printf("%s",(i<n)?" ":"\n");
- }
- return ;
- }
PAT (Advanced Level) 1064. Complete Binary Search Tree (30)的更多相关文章
- PAT甲级:1064 Complete Binary Search Tree (30分)
PAT甲级:1064 Complete Binary Search Tree (30分) 题干 A Binary Search Tree (BST) is recursively defined as ...
- PAT题库-1064. Complete Binary Search Tree (30)
1064. Complete Binary Search Tree (30) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- 【PAT甲级】1064 Complete Binary Search Tree (30 分)
题意:输入一个正整数N(<=1000),接着输入N个非负整数(<=2000),输出完全二叉树的层次遍历. AAAAAccepted code: #define HAVE_STRUCT_TI ...
- 1064. Complete Binary Search Tree (30)【二叉树】——PAT (Advanced Level) Practise
题目信息 1064. Complete Binary Search Tree (30) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B A Binary Search Tr ...
- pat 甲级 1064. Complete Binary Search Tree (30)
1064. Complete Binary Search Tree (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- PAT 甲级 1064 Complete Binary Search Tree (30 分)(不会做,重点复习,模拟中序遍历)
1064 Complete Binary Search Tree (30 分) A Binary Search Tree (BST) is recursively defined as a bin ...
- PAT Advanced 1064 Complete Binary Search Tree (30) [⼆叉查找树BST]
题目 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following proper ...
- 1064 Complete Binary Search Tree (30分)(已知中序输出层序遍历)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...
- PAT Advanced 1099 Build A Binary Search Tree (30) [⼆叉查找树BST]
题目 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following proper ...
随机推荐
- Sikuli:创新的图形化编程技术
Sikuli是一种使用截图进行UI自动化测试的技术.Sikuli包括sikul脚本,基于Jython的API以及sikuli IDE.Sikuli可以实现任何你可以在显示器上看到ui对象的自动化,你可 ...
- wmic应用实例
实例应用 1.磁盘管理 查看磁盘的属性 wmic logicaldisk list brief ::caption=标题.driveID=驱动器ID号.model=产品型号.Partitions=分区 ...
- JavaScript高级程序设计:第七章
函数表达式 1.函数表达式的特征: 定义函数的方式有两种:一种是函数声明,另一种就是函数表达式.函数声明的语法是这样的: function functionName(arg0,arg1,arg2){ ...
- hdu_5793_A Boring Question(打表找规律)
题目链接:hdu_5793_A Boring Question 题意: 自己看吧,说不清楚了. 题解: 打表找规律 #include<cstdio> typedef long long l ...
- hdu_5727_Necklace(二分匹配)
题目连接:hdu_5727_Necklace 题意: 有2*n个珠子,n个阳珠子,n个阴珠子,现在要将这2n个珠子做成一个项链,珠子只能阴阳交替排,有些阳珠子周围如果放了指定的阴珠子就会变坏,给你一个 ...
- PAXOS may not terminate
It’s easy to see that Paxos does have a failure mode. When two proposers are active at the same time ...
- OC画笔CGContextRef
1.画线 CGContextRef context = UIGraphicsGetCurrentContext();//context相当于画布 CGContextSetStrokeColorWith ...
- 数据库NULL和 ‘’ 区别
NULL判断时 : IS NOT NULL ''判断时: !=''
- MFC下对串口的操作以及定时器的调用
最近研究了一下MFC下对串口的操作,测试了一下对设备的读写. 1.打开串口 GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(FALSE); m_hComm = ...
- javascript string去除两边空格
function trim(){ return this.replace(/(^\s*)|(\s*$)/g,""); g整个字符串 }