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 ...
随机推荐
- Shell 运算符 if
Shell 支持多种运算符,包括: 算术运算符 原生bash不支持简单的数学运算,可以使用 expr,let 关系运算符 布尔运算符 字符串运算符 文件运算符 算术运算符 包括加减乘除,取余(%).赋 ...
- Mac环境下Android Studio配置Git以及最基本使用
Git是分布式版本管理工具,现在使用十分广泛,相对于SVN,GIT的使用更加方便,在离线环境下,仍然可以进行版本控制工作.且速度十分快.在Windows下,先需要自行安装Git程序,网址git-scm ...
- Flask 分页的简单用法 / flask_sqlalchemy /无刷新翻转页面(原创)
flask_sqlalchemy对象提供分页方法 1. 后台views代码: from models import <table_name> #导入model的对象 @app.route( ...
- LeetCode OJ:Lowest Common Ancestor of a Binary Tree(最近公共祖先)
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...
- MySQL学习笔记2018-02-07更新
前言:本人wechat:YWNlODAyMzU5MTEzMTQ=. 如果内容有错,请指出来. win10下安装 https://dev.mysql.com/downloads/mysql/下载并解压m ...
- canvas - 柱子效果
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- iOS7.1以后企业应用发布需要HTTPS协议,解决步骤
操作系统是Window下. 第一步安装软件 1.安装Tomcat6.0.35(Tomcat7.0.34测试通过) 2.安装JDK6(1.6.0_10-rc2,其它版本没测试) 3.安装openssl ...
- jdk1.8 HashMap 实现 数组+链表/红黑树
转载至 http://www.cnblogs.com/leesf456/p/5242233.html 一.前言 在分析jdk1.8后的HashMap源码时,发现网上好多分析都是基于之前的jdk,而Ja ...
- dojo chart详解
Dojo提供了一套很完善的统计图(Chart)接口,在dojox/charting下面,可以支持很多种类型的. .简介 Dojo统计图提供快速的.简单的接口实现美观的.交互性强的web统计图表的实现. ...
- [置顶]
【机器学习PAI实践三】雾霾成因分析
一.背景 如果要人们评选当今最受关注话题的top10榜单,雾霾一定能够入选.如今走在北京街头,随处可见带着厚厚口罩的人在埋头前行,雾霾天气不光影响了人们的出行和娱乐,对于人们的健康也有很大危害.本文通 ...