The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off. Now it's your turn to prove that YOU CAN invert a binary tree! Input Specif…
题意: 输入一个正整数N(<=10),接着输入0~N-1每个结点的左右儿子结点,输出这颗二叉树的反转的层次遍历和中序遍历. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ][]; ]; void bfs(int r){ queue<int>q; q.push(r); cout<<r; while(!q.empty()){ in…
The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off. Now it's your turn to prove that YOU CAN invert a binary tree! Input Specif…
题目 The following is from Max Howell @twitter: Google: 90% of our engineers use the sofware you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck of. Now it's your turn to prove that YOU CAN invert a binary tree! Input Speci…
1102 Invert a Binary Tree(25 分) The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off. Now it's your turn to prove that YOU CAN in…
The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off. Now it's your turn to prove that YOU CAN invert a binary tree! Input Specif…
The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off. Now it's your turn to prove that YOU CAN invert a binary tree! Input Specif…
The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off. Now it's your turn to prove that YOU CAN invert a binary tree! Input Specif…
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 (≤) which is the total number of nodes in the tree -- and he…
题目 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 - a…
题意: 输入一个正整数N(<=20),代表结点个数(0~N-1),接着输入N行每行包括每个结点的左右子结点,'-'表示无该子结点,输出是否是一颗完全二叉树,是的话输出最后一个子结点否则输出根节点. trick: 用char输入子结点没有考虑两位数的结点…
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; struct Node { int left; int right; }s[]; int n;…
就是把输入给的左孩子右孩子互换一下,然后输出层次遍历和中序遍历. #include <iostream> #include <algorithm> #include <cstring> #include <string.h> #include <cstdio> #include <queue> using namespace std; ; bool first=true; struct Node{ int id; int left;…
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. Figures 1-4 illust…
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population. Input Specification: Each input file contains one test ca…
Source: PAT A1102 Invert a Binary Tree (25 分) Description: The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off. Now it's your tu…
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90577042 1102 Invert a Binary Tree (25 分)   The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary…
1102. Invert a Binary Tree (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a…
此文章同步发布在CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90317830   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…
1043 Is It a Binary Search Tree (25 分)   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 subtree of a…
题目 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 subtree of a node contains only nodes with keys gre…
PAT甲级:1066 Root of AVL Tree (25分) 题干 An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to rest…
1066 Root of AVL Tree (25 分)   An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore th…
1102 Invert a Binary Tree The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off. Now it's your turn to prove that YOU CAN invert a…
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/668 5-6 Root of AVL Tree   (25分) An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they d…
Invert a binary tree 翻转一棵二叉树 假设有如下一棵二叉树: 4  / \   2    7  / \   / \ 1  3 6  9翻转后: 4     /    \    7     2   / \    / \  9  6  3  1 这里采用递归的方法来处理.遍历结点,将每个结点的两个子结点交换位置即可. 从左子树开始,层层深入,由底向上处理结点的左右子结点:然后再处理右子树 全部代码如下: public class InvertBinaryTree { public…
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 nu…
Invert a Binary Tree pat-1102 import java.util.Arrays; import java.util.Queue; import java.util.Scanner; import java.util.concurrent.LinkedBlockingQueue; /** * @Author WaleGarrett * @Date 2020/9/5 20:04 */ public class PAT_1102 { static InvertTree[]…
PAT乙级:1090危险品装箱(25分) 题干 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清单,需要你检查每一张集装箱货品清单,判断它们是否能装在同一只箱子里. 输入格式: 输入第一行给出两个正整数:N (≤104) 是成对的不相容物品的对数:M (≤100) 是集装箱货品清单的单数. 随后数据分两大块给出.第一块有 N 行,每行给出一对不相容的物品.第二块有 M 行,每行给出一箱货物的清…
PAT乙级:1070 结绳 (25分) 题干 给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段绳子串连.每次串连后,原来两段绳子的长度就会减半. 给定 N 段绳子的长度,你需要找出它们能串成的绳子的最大长度. 输入格式: 每个输入包含 1 个测试用例.每个测试用例第 1 行给出正整数 N (2≤N≤104):第 2 行给出 N 个正整数,即原始绳段的长度,数字间以空格分隔.所有整数都不…