• 2024-06-11Dragon Boat Festival
    DragonBoatFestival,oneofthetraditionalChinesefestivals,isdatedonthefifthdayofthefifthlunarmonth.Thisfestivalhasmanyaliases,includingNoonFestival,ChongwuFestival,MayFestival,andsoon.OnthedayofDragonBoatFestival,It
  • 2024-06-07二叉链表---二叉树的简单实现
    实验内容将二叉链表视为森林的孩子兄弟链表,计算森林中叶子个数。代码实现#define_CRT_SECURE_NO_WARNINGS1#include<stdio.h>#include<stdlib.h>#include<string.h>#defineElemTypeinttypedefstructBtree{ ElemTypeelem; structBtree*lchild,*rchild
  • 2024-05-10CF1385F Removing Leaves 题解
    看到题,感觉像树形DP,遂设计DP式子。\(dp_u\)表示以\(u\)为根的子树内最多能删多少次(不删\(u\))。那么每次子节点到父节点增加的贡献就是\(\lfloor\frac{子树大小为1的子节点个数}{k}\rfloor\)。得出式子\(dp_u=\sum_{v\inson_u}dp_v+(\sum_{v\inson_u}[dp_v\times
  • 2024-03-08Codeforces Round 656 (Div. 3) F. Removing Leaves
    ProblemDescription给出一棵\(n\)个节点的无根树。你可以进行以下操作:选择\(k\)个共同父节点的叶子节点,将\(k\)个节点和与父节点相连的边删去。求最大操作次数。Input第一行输入一个整数\(t\)\((1\let\le2\times10^4)\),表示测试组数。接下来每组测试数据第
  • 2024-02-07CF1385F Removing Leaves 题解
    解题思路简单贪心,优先选择叶子节点最多的,这样能够保证一定能把所有能删的都删了。因为要建一个可删除的图,所以我们可以使用set来存边,不然就需要维护一堆东西……那么我们肯定是从有叶子节点的点向父亲更新的,那么我们每次选择叶子节点最多的点,然后删除\(k\)个叶子,判断一下删
  • 2023-12-16D - Erase Leaves
    D-EraseLeaveshttps://atcoder.jp/contests/abc333/tasks/abc333_d 思路把这个图看成一棵树,1作为树根,统计1树根关联的子节点作为根的子树的总节点数,去除子树中总节点数最大子的子树,其它子树的总节点记做贡献,最后+1(对应1节点)。 同时注意一个特殊情况,1仅有一
  • 2023-09-01COMP3610编程技巧几点看法
    COMP3610/6361PrinciplesofProgrammingLanguagesAssignment1ver1.1SubmissionGuidelinesDuetime:Aug31,2023,11am(CanberraTime)SubmitapdfviaWattle.Scansofhand-writtentextarefine,aslongastheyarereadableandneat.Pleasereadandsign
  • 2023-08-28CF1385 F. Removing Leaves 换根dp
    CF1385F.RemovingLeaves换根dp题目链接题意:给你一棵树,有一种操作,选择k个叶子,若叶子节点的父亲相同,则可删去这k个节点,问你最多能操作多少次。做法:这题的官方做法是贪心+bfs,不过用换根dp的方法也是可做的。首先我们常规选择节点1为根节点,跑一遍dfs,主要记录下面这些变量
  • 2023-07-11PAT-甲级-1004 Counting Leaves C++
    Afamilyhierarchyisusuallypresentedbyapedigreetree.Yourjobistocountthosefamilymemberswhohavenochild.InputSpecification:Eachinputfilecontainsonetestcase.Eachcasestartswithalinecontaining 0<N<100,thenumberofnode
  • 2023-05-20Uva--699 The Falling Leaves,(二叉树的递归遍历)
    记录10:462023-5-20http://uva.onlinejudge.org/external/6/699.htmlreference:《算法竞赛入门经典第二版》例题6-10二叉树的层次遍历,边读边写(这些题给我感觉是非常灵活),对每个节点需要的数据就是在sum数组的位置#include<cstdio>#include<iostream>#include<sstream>#d
  • 2023-05-01PAT Advanced 1004. Counting Leaves
    PATAdvanced1004.CountingLeaves1.ProblemDescription:Afamilyhierarchyisusuallypresentedbyapedigreetree.Yourjobistocountthosefamilymemberswhohavenochild.2.InputSpecification:Eachinputfilecontainsonetestcase.Eachcases
  • 2023-04-30CF51F Caterpillar题解
    题目传送门题意:定义毛毛虫为一种特殊的树,形如一条链上挂着若干个叶子。特殊地,在本题中的毛毛虫允许自环但不允许重边。给定一个无向图,每次操作可以合并两个点以及两个点的出边(两个点有相同出边则出现重边,两个点之间有边则出现自环)。求将其变为毛毛虫的最小操作次数。容易发现,
  • 2023-02-23PAT 甲级 1004 Counting Leaves(30)
    Afamilyhierarchyisusuallypresentedbyapedigreetree.Yourjobistocountthosefamilymemberswhohavenochild.InputSpecification:Eachinputfilec
  • 2023-02-16【算法】青蛙从河边跳到对岸,河中需要依次落满树叶
    Codility中有这样一个算法题,是说一只青蛙从河边(position=0)跳到河的对面去(position:x+1),河边有棵树,会在不同的时间点(以秒计算)落下树叶在河面上,我们需要保证河
  • 2023-02-08【HDU6867】Tree 2020多校赛9(树形DP,贪心,爆搜)
    problemTreeTimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/65536K(Java/Others)TotalSubmission(s):126AcceptedSubmission(s):65ProblemDescript
  • 2023-01-03[LeetCode] 1325. Delete Leaves With a Given Value 删除给定值的叶子结点
    Givenabinarytree root andaninteger target,deleteallthe leafnodes withvalue target.Notethatonceyoudeletealeafnodewithvalue target, 
  • 2022-12-27404. Sum of Left Leaves
    Giventherootofabinarytree,returnthesumofallleftleaves.Aleafisanodewithnochildren.Aleftleafisaleafthatistheleftchildofanother
  • 2022-12-05LeetCode: 310. Minimum Height Trees
    LeetCode:310.MinimumHeightTrees题目描述Foranundirectedgraphwithtreecharacteristics,wecanchooseanynodeastheroot.Theresultgraphisthenaro
  • 2022-12-05Counting Elements - FrogRiverOne
    QuestionAsmallfrogwantstogettotheothersideofariver.Thefrogisinitiallylocatedononebankoftheriver(position0)andwantstogettotheop
  • 2022-11-07dmitryikh/leaves 的go版本例子
    packagemlimport( "github.com/dmitryikh/leaves")varmodelML*leaves.Ensemble//初始化加载模型funcinitML(){ ifmodelML!=nil{ return } useT
  • 2022-10-27PAT_甲级_1004 Counting Leaves (30分) (C++)
    目录​​1,题目描述​​​​题目大意​​​​输入:​​​​输出:​​​​2,解题思路​​​​关键:​​​​存储结构:​​​​dfs算法实现:​​​​3,代码【C++】​​1,题目描述 Samp
  • 2022-09-04404.sum-of-left-leaves 左叶子之和
    注意判断左叶子的条件classSolution{private:intget_sum(TreeNode*root,intsum){if(root->left!=nullptr&&root->left->left==nullptr&&
  • 2022-08-20[Google] LeetCode 366 Find Leaves of Binary Tree
    Giventherootofabinarytree,collectatree'snodesasifyouweredoingthis:Collectalltheleafnodes.Removealltheleafnodes.Repeatuntilthetre