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 ...
随机推荐
- koa2使用&&中间件&&angular2的koa托管
文章导航 1,koa2使用: 2,写中间件: 3,koa2路由配置angular2; 一.先上代码,一篇,看完koa2中大多基础方法: const Koa=require('koa'); const ...
- unity 使用MVC模式
这两天看了下老大的项目,他基本都是用MVC模式,写的很好,在此把我理解的记录下来 Model:实体对象(对应数据库记录的类) View:视图 presenter(controller):业务处理 vi ...
- jquery attr与prop的区别与联系
最近开发中发现用attr无法设置checkbox的选中事件,在网上找了下说要用prop,所以总结下两者的区别. 1.操作的对象不同 attr:操作的是HTML文档节点属性 prop:操作的是js对象属 ...
- 本地动态SQL
(转自:http://blog.itpub.net/26622598/viewspace-718134) 一.什么是动态SQL 大多数PL/SQL都做着一件特殊的结果可预知的工作.例如,一个存储过程可 ...
- 服务器证书安装配置指南(IIS7.0)
一. 生成证书请求 1. 进入IIS控制台 进入IIS控制台,并选择服务器的服务器证书设置选项. 2. 添加证书请求 进入服务器证书配置页面,并选择“创建证书申请” 3. ...
- Python基础学习(第9天)
第九课:动态类型 1.在Python中,有一类特殊的对象,是专门用来存储数据的,常见的有数字.字符串.数列.字典等.这些对象是存储在内存中的实体,我们并不能直接接触到它们,在程序中接触的是对象名,是指 ...
- 《深入理解java虚拟机》学习笔记之虚拟机即时编译详解
郑重声明:本片博客是学习<深入理解java虚拟机>一书所记录的笔记,内容基本为书中知识. Java程序最初是通过解释器(Interpreter)进行解释执行的,当虚拟机发现某个方法或代码块 ...
- mysql锁之Next-Key Locks
一个Next-key锁结合了行锁和gap锁. InnoDB执行一个行级别锁在这样的一个途径,那就是它搜索或者扫描一个表索引时,它设置共享或者独占锁在它遭遇的索引记录上.于是,行级锁是真实的行记录锁.一 ...
- 配置文件Struts.xml 中type属性 redirect,redirectAction,chain的区别
1.redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失. 2.redirectAction:action处理完后重定向到一 ...
- request.getDispatcher().forward(request,response)和response.sendRedirect()的区别
在进行web开发时,跳转是最常见的,今天在这里来学习下2种跳转: 第一种是request.getDispatcher().forward(request,response): 1.属于转发,也是服务器 ...