POJ 1287 Networking(最小生成树kruskal)

【代码超详解】POJ 1251 Jungle Road × POJ 1287 Networking(Kruskal 算法求最小生成树 · 模板 · 需要用到:并查集) 一、题目描述 Jungle Roads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 38835 Accepted: 18281(2020/3/19) Description The Head Elder of the tropical island of Lagrishan has a problem. A burst ... 阅读详情

Networking

题目链接:

http://poj.org/problem?id=1287

解题思路:

题目大意:

给你p个节点,和r条边,这r条边代表从u节点到v节点电缆的长度,现在要你将所有节点都连起来,并且使长度最小。

最小生成树裸题。

AC代码:

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

const int maxn = 105;
int p,r;
int pa[55];

struct Edge{
    int u,v,w;
}edge[maxn];


bool cmp(Edge a,Edge b){
    return a.w < b.w;
}

int findset(int x){
    if(pa[x] != x)
        pa[x] = findset(pa[x]);
    return pa[x];
}

int kruskal(){
    int cnt = p,sum = 0;
    for(int i = 0; i < r; i++){
        int u = findset(edge[i].u);
        int v = findset(edge[i].v);
        if(u != v){
            sum += edge[i].w;
            pa[v] = u;
            if(--cnt == 0)
                break;
        }
    }
    return sum;
}

int main(){
    while(scanf("%d",&p),p){
        for(int i = 0; i <= p; i++)
            pa[i] = i;
        scanf("%d",&r);
        int u,v,w;
        for(int i = 0; i < r; i++)
            scanf("%d%d%d",&edge[i].u,&edge[i].v,&edge[i].w);
        sort(edge,edge+r,cmp);
        printf("%d\n",kruskal());
    }
    return 0;
}


AWSIM模拟器 新增多相机 本文介绍了基于Unity6引擎对AWSIM自动驾驶模拟器的优化方案,主要针对多相机系统的扩展实现。作者通过修改EgoVehicle.cs和AutowareSimulationDemo.cs核心代码,将原单相机系统升级为5相机配置。关键技术点包括:1)使用List容器管理多个CameraSensor组件;2)完善相机初始化流程;3)配置5个相机UI显示窗口;4)修改ROS话题设置。优化后的系统可支持BEVFusion等多传感器融合算法的测试验证,为Autoware.universe 0.45.0及以上版本提供 阅读详情

相关推荐

STM32——LCD—FSMC原理简介

STM32——LCD—FSMC原理简介

weixin_62584795的博客 2991

POJ 1287 Networking(最小生成树)

DescriptionYou are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect

linlinsong—ACM界蒟水! 460

关于RT-Thread中PWM无法正常输出的学习

按照官方的PWM配置,并没有输出PWM,网上有比较多的办法,试了很多,有些还是不能实现输出,这里做个记录。记录自己完成PWM输出的过程,以及修改的地方。 关于STM32CubeMX配置就不多说了,网上有很多。 首先必定是按照流程来,一定一定按照流程来!!! 需要注意的是加上通道数!!!! 这是流程上没有的,也是RTT的一点小BUG吧 配上board.c中添加的代码,我用的是PA2定时2的通道3,需要使用的朋友修改对应定时器和GPIO! void HAL_TIM_Base_MspInit(TIM_Han

weixin_42566346的博客 3558

poj-1287 不是题目水,而是数据弱

这个题目很简单,就是最简单的最小生成树,并且用克鲁斯卡尔算法很容易。 但是,题目中说的边可能是无限的(The number of possible routes is unlimited),如果边有很多,该如何办呢?   当然,这里直接开10000条以上就行了,因为测试用例有限,加入10^10条呢? 这里说了最多50个点,那么最多也就1225条边,再多就是重复的,实际上我们只需要开这么大的

zhang20072844的专栏 707

本届挑战赛亚军方案:基于大模型和多AGENT协同的运维

我们分别构建了异常检测基础模型,一旦系统接受到异常即会通知LLM主管Agent,主管Agent对异常问题进行决策与子领域Agent进行桥接,多个子领域Agent协同工作,实现运维故障自动诊断和多个任务模型的编排,提升运维效率。

weixin_52705010的博客 2299

彩虹期权定价

彩虹期权的定价较为复杂,因为它涉及多个标的资产的联合分布。蒙特卡洛模拟(Monte Carlo Simulation):通过模拟多个标的资产价格路径,计算期权的预期支付。解析近似方法:如马尔可夫链近似方法或多变量Black-Scholes公式的扩展。数值方法:如有限差分法或傅里叶变换法,适用于某些特定条件下的多资产期权定价。由于彩虹期权涉及多个标的资产,我们通常使用蒙特卡洛模拟来进行定价。接下来,我将演示如何使用Heston模型和蒙特卡洛模拟方法来定价彩虹期权。

智能科技前沿 1866

poj 1287 Networking(prim or kruscal最小生成树)

题意给你点与点间距离,求最小生成树。

渐近自由 775

倍福TC3 PLC高速采集实战:如何用PLC-Recorder实现0.24ms级时间戳同步

本文详细介绍了倍福TC3 PLC与PLC-Recorder实现0.24ms级时间戳同步的工程实践方案。通过硬件拓扑设计、时间源选择优化、报文结构封装及同步验证方法,为工业自动化领域的高精度数据采集提供了可靠解决方案,特别适用于精密装配、激光切割等微秒级同步要求的场景。

weixin_29193359的博客 377

【POJ 1287】 Networking 最小生成树 Kruskal

Networking Time Limit:1000MS Memory Limit:10000K Total Submissions:18219 Accepted:9436 Description You are assigned to design network connections between certain points in a ...

天才小熊猫的博客 214

C#上位机与西门子PLC全链路通信实战教程:数据采集+SQL存储+数据库报表查询+报警历史完整实现

在工业自动化领域,西门子PLC(S7-200Smart/1200/1500)凭借稳定的性能、强大的功能、完善的生态,稳居工业控制器的主流地位;而凭借开发效率高、界面美观、兼容性强、数据库操作便捷的优势,成为工业上位机开发的首选编程语言。二者的组合,是目前制造业、自动化产线、智能仓储、暖通自控等场景的绝对主流方案,也是工业上位机工程师必须吃透的核心技术栈。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1871

车载摄像头EMC问题剖析

车载摄像头作为智能驾驶核心部件,其EMC问题日益突出。某案例中,摄像头在48MHz~175MHz频段辐射超标。通过控制变量法排查,发现网络变压器地环路和共模抑制不足是主因。整改措施包括优化接地隔离、增加共模滤波器和使用屏蔽网线,最终通过EMC测试。案例表明,EMC问题需从系统耦合角度解决,建议设计阶段预防地环路,在高速信号链中加入滤波隔离措施。全文150字。

硬核科技 278

POJ - 1287 Networking 【最小生成树Kruskal】

You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of p...

NoobPlayer_llke的博客 260

训练救星!EMA多尺度注意力让YOLOv11轻松攻克自定义数据集不涨点难题

在目标检测模型训练中,自定义数据集不涨点是阻碍算法落地的核心痛点之一。传统训练策略在数据分布特殊、样本量有限的场景下极易陷入收敛停滞,而 EMA(指数移动平均)结合多尺度注意力的方案,在自定义数据集上实现mAP 提升 6.5%,同时让训练曲线从“平缓停滞”转为“持续攀升”,彻底解决创新点在自有数据上的性能瓶颈。本教程将带你从原理到实践,通过 EMA 多尺度注意力为 YOLOv11 注入训练稳定性,让你的自定义数据集模型训练实现质的飞跃。EMA 衰减率:小样本数据集建议将decay。

FJN110的博客 164

POJ 1287:Networking(最小生成树Kruskal)

Networking Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5976   Accepted: 3231 Description You are assigned to design network connections bet

TOKHE的专栏 949

深度学习工具包 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")

Statistics and Machine Learning Toolbox

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

POJ 1287 Networking 【最小生成树Kruskal】

Networking Description You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables th...

weixin_33851177的博客 160

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

B - Networking POJ - 1287( 最小生成树 kruskal )

B - Networking POJ - 1287( 最小生成树 kruskal ) You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible rout...

石旭先森的博客 225

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

POJ1287 Networking (Kruskal与并查集求解最小生成树)

 Description You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may c

ChenYitian 724

poj1287 Networking 最小生成树,kruskal

题目链接:http://poj.org/problem?id=1287 题目

basement_boy 617

poj 1287 Networking 最小生成树 Kruskal & Prim

关于Kruskal和Prim在前面已经有详细的解释以及模板了 有关于需要注意的地方,以及在代码中注释出来。 //Kruskal //用结构体保存起始点以及耗费,然后排序后,根据Kruskal #include<iostream> #include<string> #include<cmath> #include<ctype.h> #include&l...

duanyuchen的博客 223

Poj 1287 Networking、最小生成树、kruskal:【题解】

Networking Time Limit: 1000MS Memory Limit: 10000K Description You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a s...

EP的别三日 298

poj 1287 Networking (最小生成树Kruskal算法)

最小生成树裸题 https://vjudge.net/contest/245213#problem/B #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int ma...

weixin_30765319的博客 207

POJ - 1287 Networking (最小生成树Kruskal)

题目:http://poj.org/problem?id=1287 题意: P(《=50)个点,R

Deadpool 492

poj1287 Networking 最小生成树模板题。prim+kruskal算法AC

You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of points. For each possible route between two points, you a

Lionel 1676

POJ1287 Networking(最小生成树,Kruskal,Prim)

题目: Networking Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10030   Accepted: 5469 Description You are assigned to design network connections

riba2534的博客 672
上一篇: POJ 1251 Jungle Roads(最小生成树kruskal)
下一篇: hdu 1561 The more, The Better(树形dp)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值