树的重心

【树形DP】树的重心详解+多组例题详解 目录定义:性质:算法分析:POJ 1655 Balancing Act(求重心)POJ 3107 GodfatherP1364 医院设置(树形DP) 定义: 树的重心也叫树的质心。对于一棵树n个节点的无根树,找到一个点,使得把树变成以该点为根的有根树时,最大子树的结点数最小。 树的重心定义为树的某个节点,当去掉该节点后,树的各个连通分量中,节点数最多的连通分量其节点数达到最小值。树可能存在多个重... 阅读详情

今天想起来学树上点分治,其实我还是不明白为啥,大概就学了一手树的重心吧2333
定义是去掉重心之后能使剩下的每个子树尽量平衡。那么先处理出每个点子树的size,然后枚举去掉每个点后最大子树最小的就是重心。最大子树包括两部分,由于dfs求size的时候是自己设定根为1的,而求重心判断的时候是以当前点为根的,所以除了正常的这个点的子树外,他的父亲所在的也作为他的一课子树

模版题
poj 1655

让你求树的重心以及这个重心最大的子树,注意相同情况下取序号小的为答案

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;

//thanks to pyf ...
//thanks to qhl ...

#define INF 0x3f3f3f3f

const int N = 2e5 + 7;

struct Edge
{
    int u, v, next;
} edge[N * 2];

int sz[N], Min, Mx[N];
int head[N];
int tot = 0;
int ans;
void init()
{
    tot = 0;
    Min = INF;
    memset(head, -1, sizeof(head));
    memset(sz, 0, sizeof(sz));
}
void add_edge(int u, int v)
{
    edge[tot].u = u, edge[tot].v = v;
    edge[tot].next = head[u];
    head[u] = tot ++;
}
void get_sz(int u, int fa)
{
    sz[u] = 1;
    Mx[u] = 0;
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == fa)
            continue;
        get_sz(v, u);
        sz[u] += sz[v];
        Mx[u] = max(Mx[u], sz[v]);
    }
}
void get_root(int r, int u, int fa)
{
    Mx[u] = max(Mx[u], sz[r] - sz[u]);
    if (Min > Mx[u] || (Min == Mx[u] && u < ans))
        ans = u, Min = Mx[u];
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == fa)
            continue;
        get_root(r, v, u);
    }
}
int main()
{
    int T;
    scanf("%d", &T);
    while (T--)
    {
        init();
        int n;
        scanf("%d", &n);
        for (int i = 1; i < n; i++)
        {
            int u, v;
            scanf("%d%d", &u, &v);
            add_edge(u, v);
            add_edge(v, u);
        }
        get_sz(1, 0);
        get_root(1, 1, 0);
        printf("%d %d\n", ans, Mx[ans]);
    }
}

poj3107

求这棵树的所有重心

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;

//thanks to pyf ...
//thanks to qhl ...

#define INF 0x3f3f3f3f

const int N = 2e5 + 7;

struct Edge
{
    int u, v, next;
} edge[N * 2];

int sz[N], Min, Mx[N];
int head[N];
int tot = 0;
int ans;
void init()
{
    tot = 0;
    Min = INF;
    memset(head, -1, sizeof(head));
    memset(sz, 0, sizeof(sz));
}
void add_edge(int u, int v)
{
    edge[tot].u = u, edge[tot].v = v;
    edge[tot].next = head[u];
    head[u] = tot ++;
}
void get_sz(int u, int fa)
{
    sz[u] = 1;
    Mx[u] = 0;
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == fa)
            continue;
        get_sz(v, u);
        sz[u] += sz[v];
        Mx[u] = max(Mx[u], sz[v]);
    }
}
void get_root(int r, int u, int fa)
{
    Mx[u] = max(Mx[u], sz[r] - sz[u]);
    if (Min > Mx[u] || (Min == Mx[u] && u < ans))
        ans = u, Min = Mx[u];
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == fa)
            continue;
        get_root(r, v, u);
    }
}
vector<int>tar;
int main()
{
    int n;
    while (scanf("%d", &n) == 1)
    {
        init();
        for (int i = 1; i < n; i++)
        {
            int u, v;
            scanf("%d%d", &u, &v);
            add_edge(u, v);
            add_edge(v, u);
        }
        get_sz(1, 0);
        get_root(1, 1, 0);
        tar.clear();
        for (int i = 1; i <= n; i++)
            if (Mx[i] == Mx[ans])
                tar.push_back(i);
        for (int i = 0; i < tar.size(); i++)
        {
            if (i)
                printf("%s", " ");
            printf("%d", tar[i]);
        }
        printf("\n");
    }
}

poj1741

男人八题楼教主的树上点分治。感觉比较精髓的是加减答案的部分,可惜。。。不是很懂

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;

//thanks to pyf ...
//thanks to qhl ...

#define INF 0x3f3f3f3f

const int N = 2e5 + 7;

struct Edge
{
    int u, v, d, next;
} edge[N * 2];

int Mx[N], sz[N], vis[N];
int head[N];
int root, Min;
int n, k;
vector<int>dis;
int tot = 0, ans = 0;

void init()
{
    memset(head, -1, sizeof(head));
    memset(vis, 0, sizeof(vis));
    tot = ans = 0;
}
void add_edge(int u, int v, int d)
{
    edge[tot].u = u, edge[tot].v = v, edge[tot].d = d;
    edge[tot].next = head[u];
    head[u] = tot ++;
}
void dfs_sz(int u, int fa)
{
    sz[u] = 1;
    Mx[u] = 0;
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == fa || vis[v])
            continue;
        dfs_sz(v, u);
        sz[u] += sz[v];
        Mx[u] = max(Mx[u], sz[v]);
    }
}
void dfs_root(int r, int u, int fa)
{
    Mx[u] = max(Mx[u] , sz[r] - sz[u]);
    if (Mx[u] < Min)
        root = u, Min = Mx[u];
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == fa || vis[v])
            continue;
        dfs_root(r, v, u);
    }
}
void get_dis(int u, int fa, int d)
{
    dis.push_back(d);
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        int w = edge[i].d;
        if (v == fa || vis[v])
            continue;
        get_dis(v, u, d + w);
    }
}
int get_ans(int u, int d)
{
    dis.clear();
    get_dis(u, 0, d);
    sort(dis.begin(), dis.end());
    int i = 0, j = dis.size() - 1;
    int res = 0;
    while (i < j)
    {
        while (dis[i] + dis[j] > k && i < j)
            j--;
        res += j - i;
        i ++;
    }
    return res;
}
void dfs(int u)
{
    Min = n;
    dfs_sz(u, 0);
    dfs_root(u, u, 0);
    ans += get_ans(root, 0);
    vis[root] = 1;
    for (int i = head[root]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (vis[v])
            continue;
        ans -= get_ans(v, edge[i].d);
        dfs(v);
    }
}
int main()
{
    while (scanf("%d%d", &n, &k) == 2)
    {
        if (n == 0 && k == 0)
            break;
        init();
        for (int i = 1; i < n; i++)
        {
            int u, v, d;
            scanf("%d%d%d", &u, &v, &d);
            add_edge(u, v, d);
            add_edge(v, u, d);
        }
        dfs(1);
        printf("%d\n", ans);
    }
}
树的重心——树形dp 树的重心(质心):对于一颗n个节点的无根树,找到一个点,使得把树变成以该节点为根的有根树时,最大节点数最少。换句话说,删除这个节点后最大连通块(一定是树)的节点数最少。 PS:首先要知道什么是树的重心,树的重心定义为:找到一个点,其所有的子树中最大的子树节点数最少,那么这个点就是这棵树的重心,删去重心后,生成的多棵树尽可能平衡.  实际上树的重心在树的点分治中有重要的作用, 可以避免N^2的 阅读详情

相关推荐

sqoop抽取mysql的数据到hive表里面,字段内容被自动截取,导致字段不全的问题解决

今天央视重新转播NBA,写篇博客纪念一下这个重要的日子,湖人的表现就呵呵了!!!! 强行转到博客的主题来 mysql的字段属性:该字段能存下的值比如:“山东” `province` varchar(3) NOT NULL COMMENT '省份' 用sqoop sqoop import --connect "jdbc:mysql://xxxxxx:3306/xxxxxx?tinyInt1isBit=false&zeroDateTimeBehavior=convertToNull..

放肆桀骜 963

P1364 医院设置 【Floyd】

题目描述 设有一棵二叉树,如图: 其中,圈中的数字表示结点中居民的人口。圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接点之间的距离为 111。如上图中,若医院建在1 处,则距离和 =4+12+2×20+2×40=136=4+12+2\times20+2\times40=136=4+12+2×20+2×40=136;若医院建在 333 处,则距离和 =4×2+13+20+40=81=4\times2+13+20+40=81=4×2+13+20+40=

ln2037的博客 596

【Unity游戏开发】SDK接入与集成——小白入门篇

一、简介   通常一款游戏开发到后期,一般都会涉及到第三方SDK的接入与集成,对于不熟悉SDK接入的同学来说,接SDK每次都是云里雾里,而熟悉SDK接入的同学又觉得不断地重复做接入SDK工作这样没有成就感,太尼玛无聊了(Android渠道一弄就十几个,直接吐血)。其实通常情况下接入SDK都是很简单的一个过程,本系列博客就让马三和大家从小白开始,从零基础开始学习如何接入SDK以及一些常见的SDK的...

weixin_34195142的博客 5763

P2986 [USACO10MAR]Great Cow Gathering G(带点权树重心/树形dp+换根dp)详解

https://www.luogu.com.cn/problem/P2986 先说带点权的树重心做法: https://blog.youkuaiyun.com/zstuyyyyccccbbbb/article/details/108558682树的重心的定义以及一些性质。 如果这个树有点权和边权怎么办? 关于边权:其实和所有边为单位1的重心一模一样。(网上搜了搜没怎么有比较详细的说明的,姑且当性质结论1) 关于点权:把”最大的子树节点数最少“改成“最大点权块最小”。 感性证明: 把这个问题转化成刚在.

代码笔记本 634

直播间人气协议算法:从批量操作到数据接口的自动化实现

本文深入解析直播间人气协议算法的实现原理与技术细节,涵盖批量账号管理、IP代理方案、用户行为模拟算法及平台数据接口调用策略。通过逆向工程分析通信协议,结合算法设计实现自动化流量提升,同时探讨风控规避与系统性能优化方案,为开发者提供合规的技术实践参考。

weixin_30505225的博客 517

python多线程实现http代理

python多线程实现http代理文章要求1.py socket模块2.py threading模块3.环境搭建3.1设置代理3.2搭建http简单服务器代码分析1.完整代码2.逻辑结构 文章要求 1.py socket模块 socket模块接触后很简单,我实现的是阻塞性的套接字。 需要了解到,连接套接字,监听套接字,和套接字accept()方法的返回值是元组 数据传递过程sock.recv(1024),sock.send()也不需要转换编码,直接以b"二进制流"传输 2.py threading模块 th

qq_43402663的博客 2508

HDU2196Computer(树的中心问题)

传送门 分析 首先题意是在一棵树T中输出每个结点的最远距离; 首先第一个dfs求出所有每个节点i在其子树中的正向最大距离和正向次大距离和d[i][0]和d[i][1](如果i节点在子树中最大距离经过了2号儿子,那么次大距离就是不经过2号儿子的最大距离)。并且还要标记c[i]=j表示节点i在其子树中的最大距离经过了节点j(即j是i的一个儿子)。 由上步我们获得了正向最大距离,正向次大距离和最...

pandeng的博客 1380

迈创cameralink采集卡安装操作说明

迈创cameralink采集卡安装操作说明MIL软件安装MIL软件下载获取MIL软件安装MIL软件安装常见问题 MIL软件安装 MIL软件下载获取 MIL软件安装 解压MIL安装包,点击MilSetup.exe开始安装,如下图所示; 备注:64位系统MIL软件可以同时安装32位和64位客户端,本文档默认安装64位客户端,64位系统安装32位MIL方法后续再展开讲(不建议这样用,很麻烦) 点击Launch Installation开始安装,64位系统,默认只安装64位MIL客户端 根据采集卡驱动,选择M

qq_23107577的博客 9348

【树的重心】2019CCPC-江西-A-Cotree

上链接:Problem - 6567(HDU归!好耶) 题意 给定两棵不连通的树,分别在其上选定两个节点并连接,使得 的值最小,其中dis(i,j)代表从节点i到节点j之间的距离。(2<=n<=100000) 分析 举个例子,给出以下一组数据 8 1 2 1 3 3 4 3 5 6 7 6 8 3 6 如图,很明显,需要连接节点3与节点6,能够使得两两节点之间的距离和最小。 顺便提一提,为什么输入数据是n个节点与n-2条边呢?因为要两棵独立树,根据树的性质,n节点的树有...

m0_59701064的博客 348

别再只用三次多项式了!用MATLAB手把手教你搞定七次多项式轨迹规划(附完整代码)

本文详细介绍了七次多项式在轨迹规划中的优势与应用,通过MATLAB实现从理论推导到实际代码的全过程。相比传统的三次多项式,七次多项式能精确控制位置、速度、加速度和加加速度,实现更平滑的运动控制,特别适用于工业机器人和数控机床等高精度场景。文章包含完整的MATLAB代码示例和优化技巧,帮助工程师快速掌握这一高级轨迹规划方法。

weixin_30872337的博客 297

V2签名预装失败原因及解决方案

GOOGLE最新的GTS要求targetSdkVersion 大于30的APK必须使用V2及以上签名。 但实际在预装过程中,GTS测试会失败。 后面发现这是由于预装方式的原因造成的。原来的预装方式是使用APK,指定APK使用预签名的方式。Android.mk如下: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := DKTest LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_TAGS

zyfzhangyafei的专栏 6303

树的重心(等权与带权)

树的重心的求法

2401_87266500的博客 2198

RK3588开发笔记-麦克风阵列多pdm通道合并成一个声卡

在音频设备的开发中,特别是在多通道音频数据处理场景中,如何将多个PDM(Pulse Density Modulation)通道整合成一个声卡设备,是一个非常具有挑战性的问题。RK3588芯片作为一款性能强大的平台,提供了对多个音频通道的支持。本文将介绍如何在RK3588上将多个PDM通道合并成一个麦克风阵列声卡,从而在Linux系统下统一管理和使用,提高多通道音频的同步性。在本文中我们主要介绍使用2通道回采+4通道mic声音采集构成一个6通道声卡,加以回声消除实现一个多麦克风阵列。

flypig has a dream! 1926

树的重心-java

主要通过深度优先搜索来完成树的重心,其中关于树的重心的定义可以结合文字多加理解。提示:以下是本篇文章正文内容,下面案例可供参考这次多看一下图示,理解各变量的意义,代码是简介,其中的意思要多加理解。

m0_63267251的博客 1769

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

C++树形DP基础—————求树的重心

题目描述: 树的重心定义为树的某个节点,当去掉该节点后,树的各个连通分量中,节点数最多的连通分量其节点数达到最小值。树可能存在多个重心。如下图(自制),当去掉点1后,树将分成两个连通块:(2,4,5),(3,6,7),则最大的连通块包含节点个数为3。若去掉点2,则树将分成3个部分,(4),(5),(1,3,6,7)最大的连通块包含4个节点;第一种方法可以得到更小的最大联通分量。可以发现,其他方案...

C2020lax的博客 1万+

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【知识总结】浅谈关于树的重心及其求法

一.树的重心定义 树的重心:找到一个点,其所有的子树中最大的子树节点数最少. 二.树的重心性质 树中所有点到某个点的距离和中,到重心的距离和是最小的,如果有两个距离和,他们的距离和一样。 把两棵树通过一条边相连,新的树的重心在原来两棵树重心的连线上。 一棵树添加或者删除一个节点,树的重心最多只移动一条边的位置。 一棵树最多有两个重心,且相邻。 三.如何求树的重心...

一只酷酷光儿的博客 6747

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

树的重心1——树的重心

题目:树的重心1树的重心的特征查找树的重心的方法。

gaomuchen_120309的博客 648

acwing 846. 树的重心

给定一颗树,树中包含 n 个结点(编号 1∼n)和 n−1 条无向边。请你找到树的重心,并输出将重心删除后,剩余各个连通块中点数的最大值。重心定义:重心是指树中的一个结点,如果将这个点删除后,剩余各个连通块中点数的最大值最小,那么这个节点被称为树的重心。输入格式 第一行包含整数 n,表示树的结点数。接下来 n−1 行,每行包含两个整数 a 和 b,表示点 a 和点 b 之间存在一条边。输出格式 输出一个整数 m,表示将重心删除后,剩余各个连通块中点数的最大值。数据范围 1≤n≤105 输入样例 9 1 2

刘小雨的博客 4042

C++ 图论之树的重心和直径

树的重心和直径的概念并不难理解。重心算法中有一个很让人灵光一现的地方,以一个节点为分割点,分为子树部分和其它部分,然后利用节点总和不变原理,就能很容易求出其子树节点数和其它部分节点数。这点非常值得我们学习。

y6123236的专栏 3648

【树论】树的重心

树的重心是使最大子树最小的节点,最多两个且相邻。通过DFS计算子树大小,考虑父方向分量,O(n)求解,用于树分治等。

zhangmohan123321的博客 967

【Awcing练习题-846. 树的重心】

个节点的无根树,找到一个点,将无根树变为以该点为根的有根树时,最大子树的结点数最小。重心定义:重心是指树中的一个结点,如果将这个点删除后,剩余各个连通块中点数的最大值最小,那么这个节点被称为树的重心。1.树中所有点到某个点的距离和中,到重心的距离和是最小的,如果有两个重心,他们的距离和一样。除了以删除的结点为根的子树外,剩下的一定只有一个连通子图,就用总的结点数减去当前子树的值。然后其中最大节点数中的最小值 所对应的方式所删除的节点就是树的重心。为根的子树的结点的个数。结点的所有儿子结点的编号的集合,

weixin_73831931的博客 2151

【算法】图论——树的重心

题目解析给定一颗树,树中包含n个结点(编号)和n-1条无向边。请找到树的重心,并输出将重心删除后,剩余各个连通块中点数的最大值。什么是重心?重心是指树中的一个结点,如果将这个点删除后,剩余各个连通块中节点的数量的最大值最小,那么这个节点被称为树的重心。补充:树和图的关系树本质上是一种特殊的图,它对应的是无环连通图。也就是说,在树中任意两个节点之间都存在路径(连通性),并且不存在回路(无环)。

m0_73904148的博客 2664

树的重心求解

首先我们先要了解什么是树的重心 树的重心定义为树的某个节点,当去掉该节点后,树的各个连通分量中,节点数最多的连通分量其节点数达到最小值。树可能存在多个重心。如下图,当去掉点1后,树将分成两个连通块:(2,4,5)(2,4,5)(2,4,5),(3,6,7)(3,6,7)(3,6,7),则最大的连通块包含节点个数为3。若去掉点2,则树将分成3个部分,(4)(4)(4),(5)(5)(5),(1,3,6,7)(1,3,6,7)(1,3,6,7)最大的连通块包含4个节点;第一种方法可以得到更小的最大联通分量。可以

Face_the_Blast的博客 1724
上一篇: 主席树入门
下一篇: hdu6162 Ch’s gift
OneDay_pyf
博客等级 码龄10年 6粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值