PAT (Advanced Level)1110 Complete Binary Tree (25分)

实战案例四:Claude Code + Excel 技能处理表格数据 Excel 是商业世界中最通用的数据工具。无论是财务报表、销售数据还是项目计划,Excel 无处不在。本案例将展示如何利用 Claude Code 的 Excel 技能,自动化处理复杂的表格数据,告别繁琐的手工操作。 阅读详情

1110 Complete Binary Tree (25分)

Given a tree, you are supposed to tell if it is a complete binary tree.

Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤20) which is the total number of nodes in the tree – and hence the nodes are numbered from 0 to N−1. Then N lines follow, each corresponds to a node, and gives the indices of the left and right children of the node. If the child does not exist, a - will be put at the position. Any pair of children are separated by a space.

Output Specification:
For each case, print in one line YES and the index of the last node if the tree is a complete binary tree, or NO and the index of the root if not. There must be exactly one space separating the word and the number.

Sample Input 1:
9
7 8
- -
- -
- -
0 1
2 3
4 5
- -
- -
Sample Output 1:
YES 8      
    
Sample Input 2:
8
- -
4 5
0 6
- -
2 3
- 7
- -
- -

Sample Output 2:
NO 1

坑点:特判n=1时的情况

#include<bits/stdc++.h>
using namespace std;
struct node{
	int data;
	int lchild,rchild;
};

const int maxn = 50;
node t[maxn];

int levelorder(int root){
	queue<int> q;
	q.push(root);
	int lastnode;
	int flag=1;
	while(!q.empty()){
		int temp = q.front();
		q.pop();
		if(flag == 0 && t[temp].lchild != -1){
			return root;
		}
		if(t[temp].lchild != -1){
			q.push(t[temp].lchild);
		}else{
			flag = 0;
		}
		if(flag == 0 && t[temp].rchild != -1){
			return root;
		}
		if(t[temp].rchild != -1){
			q.push(t[temp].rchild);
		}else{
			flag = 0;
		}
		if(q.empty()) lastnode = temp; 
	}
	return lastnode;
}

int main(){
	int n;
	scanf("%d",&n);
	if(n==1){
		printf("YES 0");
		return 0;
	}
	int exist[n];
	fill(exist,exist+n,0);
	string lchild,rchild;
	for(int i=0;i<n;i++){
		cin>>lchild>>rchild;
		t[i].data = i;
		if(lchild!="-"){
			exist[stoi(lchild)] = 1;
			t[i].lchild = stoi(lchild);
		}else{
			t[i].lchild = -1;
		}
		if(rchild!="-"){
			exist[stoi(rchild)] = 1;
			t[i].rchild = stoi(rchild);
		}else{
			t[i].rchild = -1;
		}
	}
	int root;
	for(int i=0;i<n;i++){
		if(exist[i] == 0){
			root = i;
		}
	}
	int flag = levelorder(root);
	if(flag == root){
		printf("NO %d",root);
	}else{
		printf("YES %d",flag);
	}
	return 0;
}
【AirPlay】苹果认证MFI学习 配件认证是一个过程,通过这个过程,可验证其配件符合MFi技术规范,并通过苹果指定的任何认证测试。MFi门户中的产品计划 "认证 "页面将指导你完成特定配件所需的认证步骤,并指出何时完成所有要求。在完成所有MFi认证要求之前,你不得制造、分发或销售任何配件。在开始MFi认证过程之前,你必须测试你的配件,以确保它符合最新的MFi技术规范,通过产品计划 "测试计划 "上的所有适用测试,并与它将声称具有兼容性的每个苹果设备兼容。 阅读详情

相关推荐

Ubuntu20.04复现instant-ngp,自建数据集,导出mesh

本次仅仅记录一下自己复现instant-ngp的过程,如果里面的参考有冒犯到原博主请联系我删除,本人也是nerf的小白一枚,可以一起交流学习神经辐射场,希望大家在复现instant-ngp的时候少走一些坑,情况允许下可以去复现一下npg-pl和nerfStudio,最后希望大家一起进步。看到一些博主说葵司的npg_pl也不错,而且葵司是台湾人,在youtube上也有讲解的视频。渲染的效果还是可以的,相对于源码来说还是有点模糊,我一些参数也没有设置,直接就拉进来进行渲染,速度是非常快的。

weixin_59961223的博客 9451

1110 Complete Binary Tree (25分) 完全二叉树 遍历

Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each input file contains one test case. For each case, the first line gives a positive integerN(≤20) which is the total number of nodes in the tree -- and henc..

haohao0626的博客 254

西门子博图编程:使用S7-1500冗余PLC 建立ModbusTCP通信

文章目录1.1 网络结构1.2 系统 IP 介绍1.3 Modbus TCP 通讯编程1.3.1 CPU 做服务器 1.1 网络结构 以 CPU151 7H 为例, 网络结构示意如下图所示: CPU 1517H 冗余 PLC 有 PROFINET X1 接口和 X2 接口, Modbus TCP 通讯可以将设备(例如 Standard PLC)通过交换机接入到任何网络接口中。如果接入 X1 接口,需要通过交换机接入到 MRP 环网中,但是并不需要支持 H-sync 转发。如果接入 X2 接口,只需要使

2万+

1110 Complete Binary Tree (25分)测试点2,3,4

Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each input file contains one test case. For each case, the first line gives a positive integer N (≤20) which is the total number of nodes in the tree – and hence t

weixin_43684570的博客 759

手把手教你用Sentinel-1和SNAP处理InSAR数据:从下载到生成沉降图(附Python脚本)

本文详细介绍了如何使用Sentinel-1数据和SNAP软件处理InSAR数据,从下载到生成地表沉降图的全流程。通过Python脚本实现自动化处理,适用于城市扩张和地质脆弱带的地表沉降监测,提供高性价比的毫米级形变监测方案。

weixin_26800111的博客 265

用Python和sklearn预测NBA比赛胜负:从数据清洗到模型优化的完整流程

本文详细介绍了如何使用Python和sklearn构建NBA比赛胜负预测模型,涵盖从数据清洗、特征工程到模型优化与部署的完整流程。通过对比随机森林、XGBoost等主流算法,提供实战技巧和解决方案,帮助数据爱好者掌握体育数据分析的核心技术。

weixin_30823001的博客 131

1110 Complete Binary Tree(判断完全二叉树)

#include<bits/stdc++.h> using namespace std; const int N=25; bool st[N]; int lson[N]; int rson[N]; int ans=0; bool bfs(int root){ queue<int> q; q.push(root); while(q.size()){ int a=q.front(); q.pop(); if(lso.

qq_44866969的博客 203

Kerberos基础及KDC服务(理论知识)

kerberos基础理论讲解+KDC服务

Siobhan_Mxin的博客 9710

PAT-ADVANCED1110——Complete Binary Tree

我的PAT-ADVANCED代码仓 https://github.com/617076674/PAT-ADVANCED 原题链接 https://pintia.cn/problem-sets/994805342720868352/problems/994805359372255232 题目描述 题目翻译 1110 完全二叉树 给定一棵树,你需要判断其是否是一棵完全二叉树。 输入...

清风阁 363

uniapp - 微信小程序接入官方人脸识别认证详细流程及示例源码,Uniapp微信小程序项目集成官方提供的人脸识别身份验证插件接口(多种示例:人脸核验、身份证件与人脸是否匹配、是否活体、实名认证等)

uni-app微信小程序人脸识别认证,使用uniapp开发微信小程序的人脸采集功能/人脸识别功能,uniapp vue3微信小程序活体人脸识别,Uni-app微信小程序实名认证,uniApp微信小程序人脸认证,UniApp的微信小程序实名认证与人脸识别系统开发,人脸核身微信小程序uni-app接入流程,wx.startFacialRecognitionVerify,uniapp开发微信小程序-人脸采集功能、微信人脸识别实名认证集成指南,识别失败,人脸识别接口怎么调用,前后端完整示例代码demo,人脸检测功能

🏆 前端领域优质创作者 3280

Midscene.js(3):手把手教你用 YAML 脚本实现 AI 驱动的 Web UI 自动化「喂饭教程」

Midscene.js是一款开源的AI驱动UI自动化工具,通过自然语言描述即可控制浏览器或Android设备执行操作。它支持YAML脚本编写测试用例,降低了自动化测试门槛。

blues_C的博客 3240

1037 Magic Coupon (25 分)(段错误原因)

The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value of that product back! What is more, the shop also offers some bonus produ

weixin_45962741的博客 495

uniapp(全端兼容) - 最新详细实现pdf在线预览功能,uniapp内置预览PDF文件功能,uniapp在安卓app|苹果app|h5网页网站|微信小程序中打开pdf进行在线预览(详细示例源码)

uni-app,安卓Android,苹果ios,App端,H5网页,移动端网站,微信小程序,支付宝小程序,nvue,vue,pdf文档,pdf文件,office,uniapp 预览pdf,uniapp怎么做pdf预览,uniapp如何实现全平台兼容的pdf在线预览,uniapp怎么在h5打开pdf文档,实现PDF在线预览,H5移动端文件预览pdf,文件下载和预览,uniapp App端pdf文件预览,app移动端在线预览pdf文件,无法预览pdf怎么办,有没有预览pdf的插件,根本打不开咋办,uniapp使

✅ 精选推荐文章 1万+

完全二叉树,满二叉树判断——PAT (Advanced Level) 1110 Complete Binary Tree (25 分)

题目概述: 给出一颗树的结构判断是否为完全二叉树 题目分析: 1.设根节点的treeindex为1,dfs遍历完树的最大treeindex(根据左右孩子的index关系)。然后判断maxtreeindex和n的关系,当且仅当两者相等的时候树中间才不会空,也就是所谓的完全二叉树,同时记录最大treeindex的curindex进行输出 2.满二叉树的判断只用在完全二叉树的基础上判断n是否为2的幂次和即可 完整代码: //完全二叉树是从上到下,从左到右的二叉树 //按孩子的规律dfs出最大的index,当且..

小楼一夜听春雨 341

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

PAT (Advanced Level) Practice A1110 Complete Binary Tree (25 分)(C++)(甲级)(判断是否为完全二叉树,sscanf)

原题链接 #include&lt;algorithm&gt; #include&lt;algorithm&gt; #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include &lt;ctime&gt; #include &lt;cmath&gt; #include &lt;vector&a

izhxxx的博客 188

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

PAT (Advanced Level) Practice 1110 Complete Binary Tree (25分) (完全二叉树的判断+分享致命婴幼儿错误)

1.题目 Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each input file contains one test case. For each case, the first line gives a positive integerN(≤...

且慢 243

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

【PAT】【Advanced Level】1110. Complete Binary Tree (25)

二叉树遍历、满二叉树

wakawaka 423

PAT (Advanced Level) Practise 1110 Complete Binary Tree (25)

1110. Complete Binary Tree (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a tree, you are supposed to tel

Occult 732

PAT (Advanced Level) Practice 1110 Complete Binary Tree 判断完全二叉树

一、概述 25分题,正常来讲应该45分钟之内做完,我用了快90分钟,日日了狗不说,还没AC。 究其原因,在于我做这道题时,只想着从最直观的角度出发,用人脑的方式,也就是我平常的判断方式,判断一棵树是否是完全二叉树,这是不行的,按我的方法: 先建树; BFS得到各节点层数以及每层的节点,按顺序; BFS得到树高; 根据树高,先从第一层到倒数第二层,看节点数量是不是满的; 若不是满的,则...

四轩茶屋 254

PAT (Advanced Level) Practice 1064 Complete Binary Search Tree (30 分)

1064 Complete Binary Search Tree (30 分) A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys ...

就当一次路过丶的沙滩 252

PAT (Advanced Level) - 1110 Complete Binary Tree

CBT、树BFS

https://www.hyperplasma.top 193

PAT (Advanced Level) Practice Complete Binary Tree

本题运用到了树的静态写法来创建树,二叉树的层序遍历来检验该二叉树是否为完全二叉树 题目 在层序遍历中,如果遇到结点为空的情况(在代码中表示为-1)的情况,则说明该树不是一棵完全二叉树,,则输出 No和根节点;如果遍历了全部的结点(均不为空),则输出Yes和最后一个结点 这是我之前刷 PTA(Advanced Level) 其他有关树的题目,从《算法笔记上机训练实战指南》中学习到如何获取根节点的方法,在这里提一下 获得二叉树的根节点编号,即0~(N-1)中未在输入中出现过的那个数。 代码如下 #inclu

题解的个人总结,仅供参考 153

PAT (Advanced Level) 1064 Complete Binary Search Tree (30 分)

题目分析: 给出一组数组,按BST顺序排好后,求他的层次遍历。 BST排好后的中序遍历即为从小到大的排序,那么此时我们可以根据中序遍历直接得到层次遍历: void Inorder(int root) { if(root >= n) return; Inorder(2 * root + 1); level[root] = inorder[t++]; Inorder(2 * root + 2); } root从0开始,按照左根右(中序)顺序给对应的level指标赋值..

小楼一夜听春雨 345

PAT (Advanced Level) 1110. Complete Binary Tree (25)

判断一棵二叉树是否完全二叉树。 #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algori...

weixin_33720956的博客 96

PAT (Advanced Level) Practice 1064 Complete Binary Search Tree(30分)【二叉搜索树BST】

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node’s key. The right sub...

一只小羊 219

PAT (Advanced Level) 1064. Complete Binary Search Tree (30) 递归建立CBST

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The righ

兔子哥哥的博客 726
上一篇: PAT (Advanced Level)1104 Sum of Number Segments (20分)
下一篇: 二叉树:已知前序序列与后序序列建树
一颗橡树
博客等级 码龄8年 23粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值