树
大白QQly成长日记
小白自远方来
展开
-
Shuffle Cards(Rope大法/平衡树)
Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards game, the very first step in the game is shuffling the cards. And, mostly the randomness in ...原创 2018-07-27 10:09:34 · 372 阅读 · 0 评论 -
Phone List(简单字典树或暴力)
DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let's say the phone catalogue listed these numbers:Emergency 911 Alic...原创 2018-07-12 11:18:15 · 3512 阅读 · 0 评论 -
Fence Repair(简单最小堆/哈夫曼树)
DescriptionFarmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer lengt...原创 2018-07-12 11:05:55 · 580 阅读 · 0 评论 -
布线问题(Prim)
描述 南阳理工学院要进行用电线路改造,现在校长要求设计师设计出一种布线方式,该布线方式需要满足以下条件:1、把所有的楼都供上电。2、所用电线花费最少 输入第一行是一个整数n表示有n组测试数据。(n<5)每组测试数据的第一行是两个整数v,e.v表示学校里楼的总个数(v<=500)随后的e行里,每行有三个整数a,b,c表示a与b之间如果建铺设线路花费为c(...原创 2018-05-29 14:03:55 · 360 阅读 · 0 评论 -
牛客小白月赛6 - H.挖沟(Kruskal)
胡队长带领HA实验的战士们玩真人CS,真人CS的地图由一些据点组成,现在胡队长已经占领了n个据点,为了方便,将他们编号为1-n,为了隐蔽,胡队长命令战士们在每个据点出挖一个坑,让战士们躲在坑里。由于需要在任意两个点之间传递信息,两个坑之间必须挖出至少一条通路,而挖沟是一件很麻烦的差事,所以胡队长希望挖出数量尽可能少的沟,使得任意两个据点之间有至少一条通路,顺便,尽可能的∑d[i][j]使最小(其中...原创 2018-08-19 10:16:57 · 301 阅读 · 0 评论 -
牛客小白月赛6 - C.桃花(DFS/BFS)
桃花一簇开无主,可爱深红映浅红。 ——《题百叶桃花》 桃花长在桃树上,树的每个节点有一个桃花,调皮的HtBest想摘尽可能多的桃花。HtBest有一个魔法棒,摘到树上任意一条链上的所有桃花,由于HtBest法力有限,只能使用一次魔法棒,请求出Htbest最多可以摘到多少个桃花。输入描述:第一行有...原创 2018-08-19 10:47:48 · 287 阅读 · 0 评论 -
求树的直径(BFS/DFS)
树的直径概念:一颗树上存在的最长路径。推导过程请参考:https://blog.csdn.net/enjoying_science/article/details/44962389代码如下(BFS版):#include<iostream>#include<stdio.h>#include<map>#include<vector>...原创 2018-08-29 18:52:08 · 1227 阅读 · 1 评论