树
Eighteen__
这个作者很懒,什么都没留下…
展开
-
1147 Heaps(甲级)
1147 Heaps (30分)In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to原创 2020-11-21 15:12:18 · 63 阅读 · 0 评论 -
1115 Counting Nodes in a BST(甲级)
1115 Counting Nodes in a BST (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 less than or equal to the node’s key.The right subtree of a原创 2020-11-21 12:18:21 · 93 阅读 · 0 评论 -
1110 Complete Binary Tree(甲级)
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原创 2020-11-20 12:28:11 · 150 阅读 · 0 评论 -
1053 Path of Equal Weigh(甲级)
1053 Path of Equal Weight (30分)Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti . The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R to any leaf no原创 2020-11-20 10:31:47 · 82 阅读 · 0 评论 -
n皇后问题
n皇后问题在n*n的棋盘上放置彼此不受攻击的n个皇后,皇后可以攻击与之在同一行,同一列,同一斜线的棋子。节点表示皇后编号,xi用来表示第i层的列数,即皇后的位置先放第一个位置,第四行则无法放置第二个位置,可以放完,为一个解依次类推,不断就进行回溯,形成树型结构#include<iostream>using namespace std;const int N=100;int x[N]{ 0 };int n,sum = 0;int place(int t)//判断原创 2020-11-20 00:22:47 · 145 阅读 · 0 评论 -
1106 Lowest Price in Supply Chain(甲级)
1106 Lowest Price in Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys prod原创 2020-11-18 22:41:36 · 69 阅读 · 0 评论 -
1004 Counting Leave(甲级)
1004 Counting Leaves (30分)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts with a line containing 0<N&原创 2020-11-18 22:35:15 · 121 阅读 · 0 评论 -
1094 The Largest Generation(甲级)
1094 The Largest Generation (25分)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 inp原创 2020-11-18 19:03:34 · 54 阅读 · 0 评论 -
1090 Highest Price in Supply Chain(甲级)
1090 Highest Price in Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys pro原创 2020-11-18 17:47:22 · 58 阅读 · 0 评论 -
1079 Total Sales of Supply Chain(甲级)
1079 Total Sales of Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys produ原创 2020-11-18 17:18:38 · 78 阅读 · 0 评论 -
1102 Invert a Binary Tree(甲级)
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 invert a原创 2020-11-18 16:41:31 · 51 阅读 · 0 评论 -
1086 Tree Traversals Again(甲级)
1086 Tree Traversals Again (25分)An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push(原创 2020-11-18 15:42:06 · 60 阅读 · 0 评论 -
堆排序
堆排序堆排序(英语:Heapsort)是指利用堆这种数据结构所设计的一种排序算法。堆是一个近似完全二叉树的结构,并同时满足堆积的性质:即子结点的键值或索引总是小于(或者大于)它的父节点。在保证是大顶堆(小顶堆)的情况下进行堆化,堆化完成后放入数组末尾#include<iostream>using namespace std;void heapfly(int *a,int n,int k){ while (1) { int maxnum = k; if (k * 2 +原创 2020-10-27 00:14:13 · 123 阅读 · 0 评论 -
二叉搜索树基本操作(增删查改)
#include<iostream>using namespace std;typedef struct Tree { int data; struct Tree* l; struct Tree* r;}*BTree;void insert(BTree root, int data){ BTree p, s, tmp=root; p = root; while (p) { tmp = p; if (data < p->data) { p =原创 2020-10-26 15:59:23 · 256 阅读 · 0 评论 -
C++学习之路 | PTA(甲级)—— 1099 Build A Binary Search Tree (30分)(带注释)(精简)
1099 Build A 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 less than the node’s key.The right subtree of a node cont原创 2020-10-14 23:17:04 · 214 阅读 · 0 评论 -
C++学习之路 | PTA(甲级)—— 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 less than the node’s key.The right subtree of a node con原创 2020-10-14 23:02:02 · 106 阅读 · 0 评论 -
C++学习之路 | PTA(甲级)—— 1043 Is It a Binary Search Tree (25分)(带注释)(精简)
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 node cont原创 2020-10-14 22:43:50 · 108 阅读 · 0 评论 -
C++学习之路 | PTA(甲级)—— 1127 ZigZagging on a Tree (30分)(带注释)(精简)
1127 ZigZagging on a Tree (30分)Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences. And it is a simple standard routine to print the原创 2020-10-13 22:50:04 · 374 阅读 · 0 评论 -
C++学习之路 | PTA(甲级)—— 1020 Tree Traversals (25分)(带注释)(精简)
1020 Tree Traversals (25分)Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.Input原创 2020-10-13 22:37:26 · 128 阅读 · 0 评论