1110 Complete Binary Tree
1110 Complete Binary Tree (25)(25 分)


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
struct Node{
int left,right;
}Tree[];
int n;
bool isCBT(int root,int &lastval)
{
;
queue<int> q;
q.push(root);
while(!q.empty()){
int top=q.front();
q.pop();
){
cnt++;
lastval=top;
q.push(Tree[top].left);
q.push(Tree[top].right);
}else {
if(cnt==n) return true;
else return false;
}
}
}
int main()
{
scanf("%d",&n);
],u[];
int left,right;
];
memset(isRoot,true,sizeof(isRoot));
;i<n;i++){
scanf("%s %s",v,u);
]==;
else{
left=atoi(v);
isRoot[left]=false;
}
]==;
else{
right=atoi(u);
isRoot[right]=false;
}
Tree[i].left=left;
Tree[i].right=right;
}
;
while(isRoot[root]==false) root++;
;
bool flag=isCBT(root,lastVal);
if(flag) printf("YES %d\n",lastVal);
else printf("NO %d\n",root);
;
}
1110 Complete Binary Tree的更多相关文章
- 1110 Complete Binary Tree (25 分)
1110 Complete Binary Tree (25 分) Given a tree, you are supposed to tell if it is a complete binary t ...
- [二叉树建树&完全二叉树判断] 1110. Complete Binary Tree (25)
1110. Complete Binary Tree (25) Given a tree, you are supposed to tell if it is a complete binary tr ...
- PAT 1110 Complete Binary Tree[判断完全二叉树]
1110 Complete Binary Tree(25 分) Given a tree, you are supposed to tell if it is a complete binary tr ...
- PAT 1110 Complete Binary Tree[比较]
1110 Complete Binary Tree (25 分) Given a tree, you are supposed to tell if it is a complete binary t ...
- PAT甲级——1110 Complete Binary Tree (完全二叉树)
此文章同步发布在CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90317830 1110 Complete Binary ...
- PAT 甲级 1110 Complete Binary Tree
https://pintia.cn/problem-sets/994805342720868352/problems/994805359372255232 Given a tree, you are ...
- 1110. Complete Binary Tree (25)
Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each in ...
- PAT 1110 Complete Binary Tree
Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each in ...
- 1110 Complete Binary Tree (25 分)
Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each in ...
随机推荐
- 在eclipse下使用maven的配置
1 2 3 4 5 6 7 8 public class Shifty { public static void main(String[] args) { int i = 0 ...
- ie if判断
<p> </p> <!--[if lt IE 7]> <html lang="en" ng-app="myApp" c ...
- 遇到不确定的json格式
我们在调用webservice接口,或者http接口时,返回的json数据,有时候会因为情况不同,返回的数据格式也不一样. 比如我在调用增加档案接口时,传入要添加的档案id,如果成功了,success ...
- Springboot项目打成war包,部署到tomcat上,正常启动访问报错404
前言: 项目介绍,此项目是一个Maven多模块项目,模块项目:all(父模块):util (公用的工具类):dao(实体类.业务类.mapper.mapper.xml):business(业务serv ...
- mongDB网址
http://www.cnblogs.com/huangxincheng/archive/2012/02/18/2356595.html
- 条款3:尽可能的使用const
const成员函数的一般好处有: 它使得class接口比较容易理解. 它使得操纵const对象成为可能. 使用的过程中应该在const与non const成员函数之间避免代码重复: class Tex ...
- JSP的三大指令
三大指令:page指令.include指令和taglib指令. page指令: * import:等同与import语句 <%@ page import="java.util.*& ...
- pip国内镜像(清华大学镜像)
网上搜到的pip国内镜像大部分是豆瓣的 http://pypi.douban.com/simple/ 但是根本不全,很多包没有 所以推荐清华大学的 https://pypi.tuna.tsinghua ...
- Debian, Ubuntu, LinuxMint 安裝 MySQL 5.7, 5.6, 5.5
以下會示範在 Debian, Ubuntu 及 LinuxMint 分別安裝 MySQL 5.7, 5.6, 5.5 的方法. 首先按照需要的安裝的 MySQL 版本, 加入相應的 Repositor ...
- 使用js构造"ddMMMyy"格式的日期供postman使用(最low的方式)
var date = new Date(); date.setDate(date.getDate() + 10); var year = date.getFullYear().toString().s ...