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 ...
随机推荐
- linux的一些操作
在终端输入cat /etc/issue 查看ubuntu的半磅不知道ubuntu特权用户root的密码时:Ubuntu在默认情况下是不启用root用户的,所以这对于一下对于linux命令不熟悉的用户在 ...
- Spring mvc使用不了jstl 或者 Spring mvc不解析jstl
最近我搭了一个maven的springMVC的项目发现前端怎么也识别不了我的jstl,我查询了很多方法,导致这种情况的原因有很多 1.jar引用不对,maven中的正确导入可用的jar <dep ...
- websocket之django简单使用
WebSocket protocol: WebSocket protocol 是HTML5一种新的协议.它是实现了浏览器与服务器全双工通信(full-duplex).HTML5定义了WebSocket ...
- "下载"文件夹的desktop.ini
下载 [.ShellClassInfo] LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21798 IconResource=%S ...
- 十 web爬虫讲解2—Scrapy框架爬虫—Scrapy安装—Scrapy指令
Scrapy框架安装 1.首先,终端执行命令升级pip: python -m pip install --upgrade pip2.安装,wheel(建议网络安装) pip install wheel ...
- deep learning新征程(二)
deep learning新征程(二) zoerywzhou@163.com http://www.cnblogs.com/swje/ 作者:Zhouwan 2016-4-5 声明 1)该Dee ...
- CSS: transitions
CSS Transitions CSS transitions allows you to change property values smoothly (from one value to ano ...
- 静态嵌套类(Static Nested Class)和内部类(Inner Class)的不同?
Static Nested Class是被声明为静态(static)的内部类,它可以不依赖于外部类实例被实例化.而通常的内部类需要在外部类实例化后才能实例化,其语法看起来挺诡异的,如下所示. /** ...
- C# 中字段和属性的使用时机
在C#中,我们可以非常自由的.毫无限制的访问公有字段,但在一些场合中,我们可能希望限制只能给字段赋于某个范围的值.或是要求字段只能读或只能写,或是在改变字段时能改变对象的其他一些状态,这些单靠字段是无 ...
- oracle的序列号(sequence)
oracle的自增列,要采用序列号(sequence). 初始化阶段要手动建立一个sequence,然后插入的时候,还要手动自己去读这个sequence的nextval赋给相关字段,如ID,麻烦的很. ...