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 ...
随机推荐
- 从 Spring Cloud 开始,聊聊微服务架构实践之路
[编者的话]随着公司业务量的飞速发展,平台面临的挑战已经远远大于业务,需求量不断增加,技术人员数量增加,面临的复杂度也大大增加.在这个背景下,平台的技术架构也完成了从传统的单体应用到微服务化的演进. ...
- cors实现跨域(.net和jquery)
本文引用自:http://blog.csdn.net/xuwei_xuwei/article/details/29845865 客户端 一个jquery cors请求例子: $.ajax({ ...
- QQ钱包,微信,京东钱包,百度钱包,支付宝AGENT
微信Mozilla/5.0 (Linux; Android 7.0; LON-AL00 Build/HUAWEILON-AL00; wv) AppleWebKit/537.36 (KHTML, lik ...
- 列出远程git的全部分支
列出全部分支 git ls-remote --heads your.git | awk 'sub(/refs\/heads\//,""){print $2}' 其中awk中sub替 ...
- iOS自动化探索(二)WDA API的使用
前面我们已经安装好了WebdriverAgent, 现在可以用Facebook官方提供的API来进行一些操作 WDA API官方页面: https://github.com/facebook/WebD ...
- java jprofile
java -agentpath:/opt/jprofiler8/bin/linux-x64/libjprofilerti.so=port=8849,nowait -Xdebug -Xrunjdwp:t ...
- 自定义音频条形图--p52
package com.zzw.qunyingzhuan2; import android.content.Context; import android.graphics.Canvas; impor ...
- LeetCode OJ:Remove Nth Node From End of List(倒序移除List中的元素)
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- LeetCode OJ:Combination Sum (组合之和)
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- CSS样式:覆盖规则
规则一:由于继承而发生样式冲突时,最近祖先获胜. CSS的继承机制使得元素可以从包含它的祖先元素中继承样式,考虑下面这种情况: <html> <head> <title& ...