ICode9

精准搜索请尝试: 精确搜索
  • pat 1004 Counting Leaves2021-01-22 10:35:51

    题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805521431773184 int k; cin>>k; //此时k输入为01 cout<<k; // 输出的k是为1的(刚开始不知道的我还用string去转化成int

  • List Leaves(二叉树的层序遍历)2021-01-11 13:04:21

     题目要求:按照从上至下,从左至右(层序)的顺序输出二叉树的叶子结点。 思路:利用队列,保存每一个结点。 先将根入队,然后将根出队,访问根结点。将根结点的儿子结点入队,后面的结点依次执行此操作,这样所有的结点都可以被访问。 队列的定义及入队出队操作如下: typedef struct Queue* SQueu

  • 1004 Counting Leaves (30分)2020-12-05 13:01:16

    题意:构建树,判断每一层节点是否有叶节点,输出每一层叶节点的数目; 第一列:第一个数是节点的总数N,第二个数是无叶子点数目M;相当于输入多少行; 接下来输入M行,第一个是父节点,接下来是子节点数目K,后面是子节点数; 第一点,需要注意定义全局变量,会自动初始化; 第二点,深度的叠加需要加在广

  • [LeetCode] 1325. Delete Leaves With a Given Value2020-12-02 03:01:06

    Given a binary tree root and an integer target, delete all the leaf nodes with value target. Note that once you delete a leaf node with value target, if it's parent node becomes a leaf node and has the value target, it should also be deleted (you ne

  • R中rpart的用法2020-11-28 21:31:43

    记录一下 rpart.plot(tree,type,fallen.leaves=T,branch,…)

  • LeetCode 310 - Minimum Height Trees (Medium)2020-11-05 03:31:44

    A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges where edg

  • LCP 19. 秋叶收藏集2020-10-01 17:04:13

    小扣出去秋游,途中收集了一些红叶和黄叶,他利用这些叶子初步整理了一份秋叶收藏集 leaves, 字符串 leaves 仅包含小写字符 r 和 y, 其中字符 r 表示一片红叶,字符 y 表示一片黄叶。出于美观整齐的考虑,小扣想要将收藏集中树叶的排列调整成「红、黄、红」三部分。每部分树叶数量可以不相

  • 树2 List Leaves2020-09-05 22:00:55

    题目: https://pintia.cn/problem-sets/1268384564738605056/problems/1274008636207132673 Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. Input Specification: Each input file contains one test case. For each ca

  • Codeforces Round #646 (Div. 2) C. Game On Leaves (贪心,博弈)2020-06-04 13:56:55

    题意:给你一棵树,每次可以去掉叶节点的一条边,Ayush先开始,每回合轮流来,问谁可以第一个把\(x\)点去掉. 题解:首先如果\(x\)的入度为\(1\),就可以直接拿掉,还需要特判一下入度为\(0\)的情况,否则,仔细想一想,因为每次都不想让对方赢,所以摘到最后,一定会出现\(x\)连的都是叶

  • C. Game On Leaves2020-06-01 22:54:16

    Ayush and Ashish play a game on an unrooted tree consisting of nn nodes numbered 11 to nn. Players make the following move in turns: Select any leaf node in the tree and remove it together with any edge which has this node as one of its endpoints.

  • Codeforces Round #646 (Div. 2) C. Game On Leaves(贪心/博弈)2020-06-01 20:58:10

    Ayush and Ashish play a game on an unrooted tree consisting of nn nodes numbered 11 to nn. Players make the following move in turns: Select any leaf node in the tree and remove it together with any edge which has this node as one of its endpoints. A leaf

  • Codeforces Round #646 (Div. 2)【C. Game On Leaves 题解】2020-06-01 12:51:28

    题意分析 关于这道题,意思就是两个人摘叶子,谁最后摘到编号为x的谁就赢了。既然是叶子,说明其最多只有一个分支,由于题目上说了是无向图,那就是度数小于等于的节点。也就是一步步移除度数小于等于的节点,直到将编号为的节点删掉游戏才结束。 那么我们可以将x这个节点作为根节点,初始时这

  • Codeforces Round #646 (Div. 2) C. Game On Leaves(树上博弈)2020-06-01 10:55:40

    题目链接:https://codeforces.com/contest/1363/problem/C 题意 有一棵 $n$ 个结点的树,每次只能取叶子结点,判断谁能最先取到结点 $x$ 。 题解 除非结点 $x$ 一开始就为叶子结点,否则二人一定会取到只剩 $3$ 个结点,且中间结点为 $x$ 的情况,判断结点 $x$ 是否为叶子结点和 $n - 3$ 的

  • 404. Sum of Left Leaves 404.左叶总和2020-05-24 10:52:52

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. 不是计算么,怎么变成recursive。好吧,还是在外面,还是算DC,就是直接

  • PAT 1004 Counting Leaves【n叉树层次遍历】2020-03-06 11:39:01

    还是代码写的少,有点手生,写了好久。。。。 题目很明了,求一个家族树上每一代人有多少没有孩子的,就是求树的每一层上有多少没有子结点的,层次遍历计数就好了。 //1004 //数组a用来存数据,第一个维度指结点编号,第二个维度中a[i][0]表示结点i是否有孩子 //a[i][1]为k,a[i][2]以及以

  • PTA | 03-树2 List Leaves (25分)2020-03-03 11:54:03

    Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. Input Specification: Each input file contains one test case. For each case, the first line gives a positive integer N (≤10) which is the total number of n

  • PAT菜鸡笔记1004 Counting Leaves2020-02-20 13:08:17

    PAT菜鸡笔记1004 Counting Leaves 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

  • 【Leetcode】1325. Delete Leaves With a Given Value2020-01-25 11:03:23

    题目地址: https://leetcode.com/problems/delete-leaves-with-a-given-value/ 删除二叉树中值为target的叶子节点。如果删除叶子后,新的叶子节点值也为target,则也要删除。返回删除后的树根。二叉树的后序遍历。先删除左子树中值为target的叶子节点,再删除右子树中值为target的

  • 1004 Counting Leaves (30分)2020-01-22 12:07:23

    BFS #include<iostream> #include<vector> #include<queue> using namespace std; struct node { int level; vector<int> child; }no[100]; int num[100]; int leveltrave(int root) { queue<int> q; q.push(root); no[root].level = 0;

  • 【leetcode】1325. Delete Leaves With a Given Value2020-01-20 15:02:45

    题目如下: Given a binary tree root and an integer target, delete all the leaf nodes with value target. Note that once you delete a leaf node with value target, if it's parent node becomes a leaf node and has the value target, it should also be delet

  • 1004 Counting Leaves2020-01-20 13:44:48

    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<100, the number of no

  • 【leetcode】1302. Deepest Leaves Sum2019-12-29 09:00:47

    题目如下: Given a binary tree, return the sum of values of its deepest leaves. Example 1: Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8]Output: 15 Constraints: The number of nodes in the tree is between 1 and 10^4. The value of nodes is between

  • Minimum Height Trees 解答2019-09-13 22:57:09

    Question For an undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called minimum height trees (MHTs). Given such a graph,

  • [LeetCode] 1123. Lowest Common Ancestor of Deepest Leaves 最深叶结点的最小公共父节点2019-08-22 22:58:15

    Given a rooted binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only if it has no children The depth of the root of the tree is 0, and if the depth of a node is d, the depth

  • 【Leetcode】1123. Lowest Common Ancestor of Deepest Leaves(二叉树最深叶子结点的公共父节点)2019-07-14 19:09:05

    Given a rooted binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only if it has no children The depth of the root of the tree is 0, and if the depth of a node is d, the depth

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有