hdu 4081 Qin Shi Huang's National Road System(次小生成树变形)

LeetCode 面试经典 150 题回顾 最经典 150 题,掌握面试所有知识点 面试经典 150 题 : 题目分析、解题思路、复杂度分析、代码展示 阅读详情

Qin Shi Huang's National Road System

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1912    Accepted Submission(s): 689


Problem Description
During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the king of the kingdom Qin. Through 9 years of wars, he finally conquered all six other kingdoms and became the first emperor of a unified China in 221 BC. That was Qin dynasty ---- the first imperial dynasty of China(not to be confused with the Qing Dynasty, the last dynasty of China). So Ying Zheng named himself "Qin Shi Huang" because "Shi Huang" means "the first emperor" in Chinese.

Qin Shi Huang undertook gigantic projects, including the first version of the Great Wall of China, the now famous city-sized mausoleum guarded by a life-sized Terracotta Army, and a massive national road system. There is a story about the road system:
There were n cities in China and Qin Shi Huang wanted them all be connected by n-1 roads, in order that he could go to every city from the capital city Xianyang.
Although Qin Shi Huang was a tyrant, he wanted the total length of all roads to be minimum,so that the road system may not cost too many people's life. A daoshi (some kind of monk) named Xu Fu told Qin Shi Huang that he could build a road by magic and that magic road would cost no money and no labor. But Xu Fu could only build ONE magic road for Qin Shi Huang. So Qin Shi Huang had to decide where to build the magic road. Qin Shi Huang wanted the total length of all none magic roads to be as small as possible, but Xu Fu wanted the magic road to benefit as many people as possible ---- So Qin Shi Huang decided that the value of A/B (the ratio of A to B) must be the maximum, which A is the total population of the two cites connected by the magic road, and B is the total length of none magic roads.
Would you help Qin Shi Huang?
A city can be considered as a point, and a road can be considered as a line segment connecting two points.
 

Input
The first line contains an integer t meaning that there are t test cases(t <= 10).
For each test case:
The first line is an integer n meaning that there are n cities(2 < n <= 1000).
Then n lines follow. Each line contains three integers X, Y and P ( 0 <= X, Y <= 1000, 0 < P < 100000). (X, Y) is the coordinate of a city and P is the population of that city.
It is guaranteed that each city has a distinct location.
 

Output
For each test case, print a line indicating the above mentioned maximum ratio A/B. The result should be rounded to 2 digits after decimal point.
 

Sample Input
2 4 1 1 20 1 2 30 200 2 80 200 1 100 3 1 1 20 1 2 30 2 2 40
 

Sample Output
65.00 70.00


 

题意:秦始皇要修路,使得各个城市之间连通。徐福可以不费人力地凭空建造一条magic路。现在要选一条路成为magic路,使得magic路的两个端点城市的人口总数A和修建的道路(不算magic路)长度总和B,满足A/B最大。求A/B最大是多少。

思路:次小生成树变形。可以证明最后的图是最小生成树或次小生成树删除一条边所得到的图。先求原图的MST,保存MST上两点(i,j)之间的路径的最大边path[i][j]。然后枚举原图的每一条边(i,j),如果该边在MST上,那么删除这条边,比值是(i的人口数+j的人口数)/(MST-G[i][j]);如果该边不在MST上,那么删除path[i][j](注意无需加入边(i,j)),比值是(i的人口数+j的人口数)/(MST-path[i][j])

 

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <cstdlib>
using namespace std;

const double INF=1000000000;
const int maxn=1005;
struct node
{
    double x,y,popu;
} p[maxn];
double G[maxn][maxn],dis[maxn],path[maxn][maxn];
int pre[maxn];
bool vis[maxn],used[maxn][maxn];
int n;
double get_dis(node a,node b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void prim()
{
    int x;
    double m,sum=0.0;
    memset(vis,false,sizeof(vis));
    memset(used,false,sizeof(used));
    memset(path,0,sizeof(path));
    for(int i=0; i<n; i++)
    {
        dis[i]=G[0][i];
        pre[i]=0;
    }
    vis[0]=true;
    for(int i=0; i<n-1; i++)
    {
        m=INF;
        for(int j=0; j<n; j++)
            if(!vis[j]&&dis[j]<m)
                m=dis[x=j];
        if(m==INF) break;
        sum+=m;
        vis[x]=true;

        used[pre[x]][x]=used[x][pre[x]]=true;
        for(int j=0; j<n; j++)
        {
            if(vis[j]&&j!=x)
                path[x][j]=path[j][x]=max(path[pre[x]][j],m);
            if(!vis[j]&&dis[j]>G[x][j])
            {
                dis[j]=G[x][j];
                pre[j]=x;
            }
        }
    }
    m=0;
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            if(i!=j)
            {
               if(used[i][j]) m=max(m,(p[i].popu+p[j].popu)/(sum-G[i][j]));
               else m=max(m,(p[i].popu+p[j].popu)/(sum-path[i][j]));
            }
    printf("%.2lf\n",m);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0; i<n; i++)
            scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].popu);
        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++)
            {
                if(i==j) G[i][j]=0;
                else
                    G[i][j]=get_dis(p[i],p[j]);
            }
        prim();
    }
    return 0;
}


 

rk3568 rk628桥片 rgb2hdmi RK628 是瑞芯微全新推出的视频桥接芯片,支持丰富的显示接口,支持高分辨率大屏产品转换需求。基于DRM、FB的显示框架易于使用。 输入信号支持:HDMI、RGB、BT.1120,输出信号支持 HDMI、GVI、Dual LVDS、Dual MIPI、MIPI-CSI、RGB、BT.1120,最高支持4K 60fps 输入/输出转换,并且支持输入到输出 1/4~4倍的缩放。 阅读详情

相关推荐

Ghidra逆向分析实战:从安装JDK到解析STM32的bin文件(附SVD插件配置)

本文详细介绍了使用Ghidra进行STM32固件逆向分析的完整流程,从JDK安装配置到SVD插件的应用。通过实战案例展示如何解析bin文件、恢复符号信息以及利用SVD插件识别外设寄存器,帮助开发者高效完成嵌入式设备的逆向工程任务。

weixin_29309475的博客 649

hdu 4081 Qin Shi Huang's National Road System (次小生成树的变形)

题目:Qin Shi Huang's National Road System Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2049    Acc

Hadis_yuki 1145

X3850x6 6241 fireware固件升级

登录联想https://datacentersupport.lenovo.com/cn/zc网站,选择system x,x3850 x6,type选择6241 选择驱动及应用程序,BIOS/UEFI 选择lnvgy_fw_uefi_a9e156a-4.90_anyos_32-64.uxz 文件,点击下载 选择IMM2, 下载lnvgy_fw_imm2_tcoo58b-5.80_anyos_noarch.uxz ps:3837和3839会跳转到ibm网站下载 笔记本直连.

zds00virtue的博客 5461

HDU4081 Qin Shi Huang's National Road System —— 次小生成树变形

题目链接:https://vjudge.net/problem/HDU-4081 Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8970...

weixin_30591551的博客 90

RT-Thread实战:手把手教你用STM32F04ZGT6通过SPI驱动BMI088(附完整工程)

本文详细介绍了如何使用RT-Thread操作系统在STM32F04ZGT6上通过SPI接口驱动BMI088高性能6轴惯性传感器(包含陀螺仪和加速度计)。从硬件连接到软件配置,再到数据采集与处理,提供了完整的开发指南和优化技巧,帮助开发者快速实现精确的姿态测量功能。

kappa的博客 239

【模型】OpenClaw 接入阿里云永久免费模型方案

Qwen2.5-7B-Instruct 模型为例。

海兰 4488

HDU 4081 Qin Shi Huang's National Road System(次小生成树变形)

Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7530    Accepted Submission(s): 2649 Problem Desc

yasolx的博客 625

【入坑存内计算一键指南】存内计算运算原理:算法优化、存储介质探究

本文探讨了存内计算及其面向的架构优化,尤其侧重于图算法优化和存内计算存储介质。文章介绍了存内计算的概念和意义,着重强调了存内计算解决了内存墙问题,提高了计算效率。针对图算法的优化,提出了基于位运算的创新方法,重塑了单源最短路径算法,并介绍了基于局部重叠度的链路预测算法优化设计。接着,文章详细讨论了存内计算存储介质,特别是非易失性存储器,比较了不同类型存储器的性能,并重点介绍了基于ReRAM的存内计算技术,包括其物理模型和交叉阵列结构。

一键难忘的博客 7078

HDU-#4081 Qin Shi Huang's National Road System(次小生成树变形)

题目大意:有n个城市,秦始皇要修n-1条路连接,要求路径最短。而徐福拥有魔法可以修一条魔法道路,不需要人力和财力花费。但是这条路是人力最多的那一条。因此秦始皇给出了一个公式A/B,A为那条路两边城市的人数,B为除这条路其它要修路的路径之和。          解题思路:之前没写过次小生成树,以为不好写,看了题解之后发现不是很难的,主要是怎么去想吧!想好了就会很简单,想不到就会很难,参见了这篇博客

VoidSun 523

RK3588 部署 YOLOv5s 实战:多线程加速从 16FPS 飙升到 120FPS(含性能优化)

因为RK3588包含了3个NPU核心,支持3个核心同时工作、双核合作、以及单核工作。我们可以使用线程池来加速。线程池是一种长街的并发编程模型,它用于管理和复用线程,以提高多线程程序的性能和效率。线程池通常包含以下主要组件:1、任务队列:任务队列用于存储待执行的任务。这些任务可以是函数、方法或其他需要多线程环境中执行的操作。2、线程池管理:线程池管理器负责创建、销毁和管理线程。它会监视任务队列中的任务,根据需要创建线程,执行任务,并在任务完成后将线程放回池中以供重用。

FJN110的博客 107

揭秘大厂智能生产调度AI系统架构:架构师拆解中台化设计3大优势

智能生产调度AI系统是基于AI算法(如遗传算法、强化学习、深度学习),结合生产数据(如订单、设备、库存、人员),自动生成最优生产计划与调度方案的系统。最大化设备利用率(减少停机时间);最小化生产周期(快速交付订单);优化库存水平(降低积压与短缺);提升准时交货率(满足客户需求)。维度传统调度系统智能调度AI系统决策逻辑规则引擎+人工经验AI算法(预测+优化)数据处理手工汇总+静态数据实时数据整合+动态更新适应能力固定场景(如单一产品、单一工厂)

AI Python 编程之道的博客 762

hdu4081-次小生成树&MST变形&模板-Qin Shi Huang's National Road System

https://vjudge.net/problem/HDU-4081 给定你一个图,和每个点的坐标,问你建设n-1条路将它们链接起来后,可以减去其中一条边的花费,设其剩下的花费为B。而这条边对应的两个点的 点权大小为 A 要求A/B尽可能的大。。 思路: 这是用prim求次小生成树的方法。 维护path[][],作为表示i到在MST上的最长边。 并且 在一个最小生成树中,加一个

天与云与山与水 259

zemax---光学设计基础概念篇(持续更新中)

光学设计相关知识概念

u011699626的博客 1147

hdu 4081 Qin Shi Huang's National Road System 【最小生成树的变形】

**Qin Shi Huang's National Road System** Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7448 Accepted Submission(s): 2621 Pro

逝去的时光 409

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Statistics and Machine Learning Toolbox

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

Hdu Qin Shi Huang's National Road System 【次小生成树变形】

http://acm.hdu.edu.cn/showproblem.php?pid=4081 题目大意:在一个完全图中找一棵生成树,满足其中一条边的两个邻接点的点权之和除以该生成树的所有比安全和的比例最大,求该比例。 设最终所要的比例为ratio,则初始是设ratio为一个小负数。首先计算出图的最小生成树,设最小生成树的总长度为ans;然后枚举所有的点对(i,j),如果边(i,j...

bantengbang8949的博客 117

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

【MST】2011 regional Beijing Site A—— Qin Shi Huang's National Road System——hdu 4081

这题可以算是MST的变形,首先求MST,作用是枚举每条边。然后A = 左子树最大值 + 右子树最大值,B = 余下长度,注意枚举的那条边不是题目中的特殊边,因为如果这样想就变成了B固定,求A的最优值,而题目中A和B都是变量,互相牵制。 我在这里不是枚举边,这样做太麻烦了,改成枚举任意两点,dfs求出两点之间边权最大的边,把它替换了。 额。。。写的有点搓,各位尽情bs吧 #include #

leolin_的专栏 644

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

hdu4081 Qin Shi Huang's National Road System

Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2025 Accepted Submission(s): 739 Problem Description

习惯与规则决定命运 1042

hdu 4081 Qin Shi Huang's National Road System(最小生成树变形)

Qin Shi Huang's National Road System Problem Description During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Y

a709743744的博客 337

HDU 4081 Qin Shi Huang's National Road System 最小生成树变形

点击打开链接 Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2234    Accepted Submission(s): 806

代码改变世界,keep coding。 1260

Hdu 4081 Qin Shi Huang's National Road System

大意: 有n个城市,秦始皇要修用n-1条路把它们连起来,要求从任一点出发,都可以到达其它的任意点。秦始皇希望这所有n-1条路长度之和最短。然后徐福突然有冒出来,说是他有魔法,可以不用人力、财力就变出其中任意一条路出来。 秦始皇希望徐福能把要修的n-1条路中最长的那条变出来,但是徐福希望能把要求的人力数量最多的那条变出来。对于每条路所需要的人力,A是指这条路连接的两个城市的人数之和,对,是...

weixin_30443075的博客 85

hdu4081Qin Shi Huang's National Road System(次小生成树)

题解:这题就是次小生成树的变形,先求出该最小生成树,然后如果这个点要和前面那个点连接的话,要把之前连接好的最大一条路给断了造成两个连通图,最后答案变成(a[i].num+a[j].num)/(b-Max[i][j])然后取其中的最大值即可。 #include #include #include #include #include using namespace std; const int mx

Soul 250

hdu 4081Qin Shi Huang's National Road System(最小生成树变形)

题目大意: 秦始皇要修建最小费用的道路,有个道士可以建一条免费魔法道路,但是道士要求这条道路连接的两个城市的人口要最多,秦始皇不同意,权衡之下决定用A/B的最大比值来修建魔法道路。 A:魔法道路连接的城市总人口 B:除魔法道路外需要修建的道路总长 先生成一棵最小生成树,枚举每条边(在A一定的情况下,B越小,A/B越大),若这条边在树上,减去这条边的权值,否则减去成环最大边的权值。

Vencc__的专栏 392

hdu 4081 Qin Shi Huang's National Road System (最小生成树变形 两种解法 1.Prim 2.dfs)

Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2027    Accepted Submission(s): 741 Problem D

To be what you what to be! 1343

Qin Shi Huang's National Road System 【HDU - 4081】【次优比例生成树(最优比例生成树变形)】

题目链接   题目问的是有N个点集,问你建立N-1条边的情况下,使得路径最短的方案数,但是呢,题目中又给出徐福会魔法可以把一条路径变成免费道路,但是有个限制就是希望这条路上两个城市的人口数比上除去该路径以外整棵树的权值能最大。   一开始就想到的是最优比例生成树,但是却有很多地方不大对,没法往下推下去,强行过了样例交了两发最后草草WA了,后来画了张图去推了下,发现了件事,我们看到样例一所给出的...

既然弱小,就只顾变强就是了 268
上一篇: hdu 4034 Graph(floyd)
下一篇: hdu 1068 Girls and Boys(最大独立集)
KinFungYu
博客等级 码龄14年 39粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值