hdu1055 Color a tree(贪心☆☆☆☆☆)

DBeaver连接ClickHouse保姆级教程:从安装到成功测试(附驱动下载问题解决) 本文提供了一份详细的DBeaver连接ClickHouse实战指南,重点解决了驱动下载失败等常见问题。文章从环境准备、DBeaver安装讲起,详细阐述了手动配置ClickHouse驱动的可靠方案,并逐步指导完成连接配置与测试,最后介绍了基础操作与查询优化技巧,旨在帮助用户高效完成连接并快速上手使用。 阅读详情

思路来源

来源①:https://blog.csdn.net/gatieme/article/details/49202739

来源②:https://www.cnblogs.com/dramstadt/p/3201984.html

题意

给你一棵树,一上来可以染根节点。

对于其他的点i,染i时必须先染i的父节点。

每个点i对应一个权值c[i],

从t=0开始染色,染i的花费=c[i]*当前时间t

现给定父子关系和根节点编号,

不妨设点i在s[i]秒被染色,染色时间为1(这里记为t[i])

即求min(\sum c[i]*s[i])

题解

显然,我们染了一个点之后,

如果它的后继点是权值最大的点,

我们立刻染权值最大的点,是最明智的选择。

 

这就意味着,不管何时染权值最大的点的前驱,

染完之后下一秒都该染权值最大的点,

即在染色序列中,权值最大的点是和它的前驱挨在一起的。

我们把这两个点绑定在一起,合二为一。

 

记点i在s[i]秒被染色,染色时间为t[i],权值为c[i],

考虑三个点的情形x y z

其中x是y的前驱,z可以直接染。

这样有两种染色方式,

c[x]+2c[y]+3c[z]①

c[z]+2c[x]+3c[y]②

 

在任意一种染色方式中,y都在x后染,

设第s[x]秒染x,cost为s[x]·c[x]

则(s[x]+1)秒染y,cost为(s[x]+1)·c[y],在这里t[x]=1,

如果我们将x和y绑定在一起的话直接求s[x]*(c[x]+c[y]),会少算1·c[y]

因此,我们每一次合并,就把染父亲节点所需时间*子节点的权值(这里是t[x]*c[y])加到sum里。

 

此外,若先不考虑随时间增长的花费,

它们都至少有c[x]+c[y]+c[z]的基础花费,我们在最初的时候把这些也加到sum里。

而选择任意一种方式,都会有y在x后染而带来的附加花费c[y]

这样最基础的花费就是c[x]+2c[y]+c[z]

 

比较基础花费和①、②的区别,发现一个多2*c[z],另一个多(c[x]+c[y])

假设这里c[x]+c[y]<2*c[z],

那么我们就应该选策略②,让z先染,

其实质是c[z]>(c[x]+c[y])/2,即单染z的时间比染x、y的平均时间长,

因此,我们优先染那些平均单点时间长的点。

 

事实上,由于c[z]大,先将z向根合并,再将(xy)合点向根合并,就达到了先染z的目的。

而实际由于先合并z的时候,根节点里只有一个点,

再合并xy的时候,根节点里有两个点,

所以对答案的贡献,大的权值*1+小的权值*2,一定比反过来更优。

这实际上,就是第一秒染z,第二秒染xy合点(由于sum里加过c[y]其实是第二秒染x第三秒染y)的等价意义。

 

所以,开一个结构体,代表节点/合并后的节点

记录一个c,是合并点的总权值\sum c[i],

记录一个t,是合并点的染点总时间\sum t[i]

每次遍历选择,v=c/t最大的,即平均时间最大的点开始染。

 

怎么叫染了这个点呢?把它和它的父节点合并。

代表染完它的祖先节点之后,立刻染这个点。

 

代码

#include <iostream>
#include <algorithm> 
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
const double INF=0x3f3f3f3f;
const int maxn=1e5+10; 
const int mod=1e9+7;
const int MOD=998244353;
const double eps=1e-7;
typedef long long ll;
#define vi vector<int> 
#define si set<int>
#define pii pair<double,int> 
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define lowbit(x) (x&(-x))
#define sci(x) scanf("%d",&(x))
#define scll(x) scanf("%lld",&(x))
#define sclf(x) scanf("%lf",&(x))
#define pri(x) printf("%d",(x))
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define mem(a,b) memset(a,b,sizeof(a)) 
using namespace std;
int n,r,sum,a,b;
struct node
{
	double v;
	int c;//c总 
	int t;//t总 
	int par;
};
node ans[1005]; 
int main()
{ 
    while(~scanf("%d%d",&n,&r)&&n+r)
    {
    	mem(ans,0);
    	sum=0;
    	rep(i,1,n)
    	{
    		scanf("%d",&ans[i].c);
    		ans[i].t=1;
    		ans[i].v=ans[i].c;
    		sum+=ans[i].c;
    	}
    	rep(i,1,n-1)
    	{
    		scanf("%d%d",&a,&b);
    		ans[b].par=a;
    	}
    	rep(i,1,n-1)//需要合并n-1次 
    	{
    		int pos=0;
    		double maxv=-1;
    		rep(j,1,n)
    		{
    			if(j==r)continue;
    			if(ans[j].v>maxv)
    			{
    				pos=j;
    				maxv=ans[j].v;
    			}
    		}
    		ans[pos].v=0;//不影响后续操作  
    		int u=ans[pos].par;
    		sum+=ans[pos].c*ans[u].t;
    		ans[u].c+=ans[pos].c;
    		ans[u].t+=ans[pos].t;
    		ans[u].v=ans[u].c*1.0/ans[u].t;
			rep(j,1,n)
    		{
    			if(ans[j].par==pos)ans[j].par=u;
    		}
    	}
    	printf("%d\n",sum);
    }
	return 0;
}

 

创龙 瑞芯微 RK3588 国产2.4GHz八核 工业开发板—ISP图像处理开发案例 创龙科技研发的 TL3588-EVM 评估板具备强大视频处理能力,可满足多场景视频开发需求。为助力开发者快速上手,本文整理 7 个实用视频开发案例,涵盖从采集到显示的全流程,详细说明各案例的硬件连接、参数配置与代码解析,帮助开发者高效实现评估板视频相关功能开发与调试。 阅读详情

相关推荐

Unity IAP插件实战:从零搭建Google Play内购系统

本文详细介绍了如何使用Unity IAP插件从零搭建Google Play内购系统,涵盖环境准备、双端配置、核心API实现及常见问题排查。通过实战代码示例,帮助开发者快速掌握跨平台内购功能开发,提升手游商业化效率。

weixin_28692867的博客 434

hdu1055 贪心

贪心好题。 1、初始时将序列中的time[i]都置为1,w[i]置为c[i]; 2、查找最大的w[i], 返回其位置; 3、将该位置的c[]与它的父节点c[]合并(合并过程就是C_i / T_i,C_i = c[该节点] + c[父节点],T_i = time[该节点]+time[父节点])得到新的父节点w[](w[父节点] = C_i / T_i),如果有节点与pos相

WJSZMRX 653

地震数据可视化必备:5分钟读懂SEGY道头字段全解析(含坐标定位指南)

本文深入解析了SEGY文件格式中道头坐标字段的提取与可视化方法。针对地震数据处理中的常见痛点,详细介绍了sx/sy、gx/gy等关键坐标字段的二进制解析、比例因子应用、单位转换及常见问题解决方案,并提供了实用的Python代码示例,帮助开发者实现从SEGY文件到三维空间可视化的完整流程。

echo99的专栏 1017

hdu1055 树最大权值贪心

做这道题有什么感觉呢?刚接触贪心的一级小白,不小心遇到了大BOSS。。。但是作为1级的小白,梦想还是要有的。 http://blog.sina.com.cn/s/blog_74e20d890100wx8d.html 放上我学习的地方,代码基本上和别人的差不多。但是好奇为啥我将sum的类型设置成double类型的,在hdu上面提交就会出现错误。 思路: 1:每次通过find_max()遍历寻...

qq_41755258的博客 475

三菱FX3U PLC红绿灯ST编程实战:从基础逻辑到急停功能完整实现

本文以十字路口红绿灯控制为例,详细讲解了三菱FX3U PLC使用ST编程的完整实战过程。内容涵盖从基础时序逻辑、状态机设计,到急停功能、黄灯闪烁、昼夜模式切换等高级功能的实现,并提供了代码优化与调试技巧,帮助工程师掌握结构化文本在工业控制中的清晰、结构化应用。

weixin_29070861的博客 541

DeepLearningTool-深度学习分类-和HALCON的详细过程

损失函数:衡量预测误差,用于模型优化。混淆矩阵:评估分类模型性能,提供详细预测结果分析。两者结合使用,可以全面评估和优化模型。过拟合:模型过于复杂,捕捉了噪声,表现为训练集误差低,测试集误差高。欠拟合:模型过于简单,无法捕捉数据模式,表现为训练集和测试集误差都高。调整参数过拟合:简化模型、增加数据、使用正则化、早停、Dropout。欠拟合:增加模型复杂度、特征工程、增加训练时间、调整学习率、使用集成方法。通过合理调整参数和方法,可以有效避免过拟合和欠拟合,提升模型性能。

weixin_36672036的博客 6217

HDU 1055(贪心)

#pragma warning(disable:4996) #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<vector> #include<algorithm> #include<iostream> #include<time.h> using namespace std;const int

JACK_JYH的博客 449

数电-基于FPGA的自动售货控制系统设计

本次数电的课程设计是设计一款基于FPGA的自动售货控制系统,因为手上暂时没有FPGA的板子,所以先采用proteus仿真进行设计,观察系统效果,等之后FPGA板子下发,再移到quartus上调试和下载。同样是自己第一次自主设计电路系统,可能在功能上不完整或者逻辑上有错误,大家多多包涵,欢迎沟通交流。

gg1067的博客 2294

hdu1055

​ #include &lt;iostream&gt; using namespace std; const int maxn=1005; struct Node{ int c,t,pre; double w; }; struct Node pp[maxn]; int find_node(int n,int r) { int ans; double v=-100;...

qq_41680251的博客 287

【PSINS】EKF、UKF、CKF三个滤波下的组合导航(松组合)对比,订阅专栏后可查看完整代码

基于PSINS的MATLAB工具箱。工具箱给的例程只有单独的EKF等滤波算法,这个程序将三种方法汇总在一起,并进行对比。EKF:扩展卡尔曼滤波UKF:无迹卡尔曼滤波CKF:容积卡尔曼滤波。

985工科博士毕业,专攻定位、导航和滤波等算法研究。从业10年,主要使用MATLAB 1914

innovus:像ICC2一样设置placement label

ICC2有placement label/placement rule功能,能控制各种类型cell 之间的spacing规则,包括top和bottom edge的spacing。innovus也有相同的功能,以下示例方便大家了解用法。我们需要给所有OAI* cell之间设置一个spacing rule,让他们不要上下或者挨着。效果如下图,这个spacing指的是同一边的间距,不是cell间距。我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?

m0_61544122的博客 851

hdu_1055 Color a Tree

题意:一棵树,父亲染色以后,这个节点才允许被染色。染色的代价= c[i]*t c[i] 表示这个点的权值,t表示这个点被染色的时间。 求最小的染色代价。 贪心策略: 选择一个点,如果这个点的权值最大,必然如果他的父亲被染色了,就一定会先染色这个点。 首先我们 那么这个节点就和他的父亲被绑定在一起了。 绑定以后,他们的权值=c[i]+c[fa[i]], 因为父亲先染色,孩子

Hzy_hzy_hzy的博客 569

【异常】‘build.plugins.plugin.version‘ for org.apache.maven.plugins:maven-resources-plugin is missing

maven-compiler-plugin 插件版本信息没有指定导致了错误提示如下字面意思就是没有指定版本信息。

奶爸的编程之路,也就一周冷个三天 4606

HDU-1055 Color a Tree(贪心策略)

HDU-1055 Color a Tree(贪心策略) Color a Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3691 Accepted Submission(s): 1359 Problem Description Bob is very interested in

aconacon的博客 284

Statistics and Machine Learning Toolbox

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

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

HDU 1055 Color a Tree 【贪心】

传送门:HDU 1055 Color a Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3183 Accepted Submission(s): 1158 Problem Description Bob is ver...

Waiting For You 506

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...

【hdu1055】【贪心】color a tree

Color a tree 题目描述 给一棵nnn个点的树,每个点有一个点权cicic_i,求一长度为nnn的排列ppp,最小化 S=∑i=1nicpiS=∑i=1nicpi S=\sum_{i=1}^nic_{p_i} 题解 设没有染色的点的集合是V0V0V_0,V0V0V_0中当前可以染色的点(即根节点)的集合为V1V1V_1。 设uuu为V0V0V_0中点权最大的点,即cu=...

function2的博客 368

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

color a tree【hdu1055】【POJ2054】贪心

POJ链接 hdu链接 Color a TreeProblem Description Bob is very interested in the data structure of a tree. A tree is a directed graph in which a special node is singled out, called the “root” of the tree,

function2的博客 768

HDU oj 1055(Color a Tree 贪心好题)

Color a Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1872    Accepted Submission(s): 654 Problem Description Bob is very in

Mad_boys的博客 659

HDU 1055 Color a Tree

Color a TreeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2099 Accepted Submission(s): 750Problem Description Bob is very interested in t

still_foolish的博客 398

HDU1055Color a tree

Color a Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2270 Accepted Submission(s): 824Problem Description Bob is very interested in

Jack_zhuiyi的博客 646

hdu1055 Color a Tree(贪心)

Color a Tree Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 563Accepted Submission(s): 206 Problem Description Bob is very interest...

angtongyou1893的博客 165

hdu 1055 Color a Tree 贪心

Color a Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1096    Accepted Submission(s): 357 Problem Description Bob is very in

G.D.Retop的专栏 1112

【HDU1055】Color a Tree

题意 给一棵树,要给树上每一个结点染色,第i 个结点染色需要代价为:t * w[i] (t 表示i 结点是第几个染色的),还有一个前提是:要给i 结点染色,必须先给i 结点的父结点染色(根结点随便染) 分析 lyd蓝书 p41例题 贪心,奇特的均分权值。 就分两种情况,若以该节点的父节点全部被涂过,且该节点是剩的最大权值的节点,则涂。 如果父节点没有被涂过,它一定会紧接着父节...

Ashley_2013的博客 155

hdu 1055 Color a Tree (树+贪心)

Color a Tree Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3080Accepted Submission(s): 1110 Problem Description Bob is very interested ...

weixin_30646505的博客 142

POJ 2054 /HDU 1055 Color a Tree(贪心+并查集)

Bob is very interested in the data structure of a tree. A tree is a directed graph in which a special node is singled out, called the "root" of the tree, and there is a unique path from the root to ea...

深海沧澜的博客 381
上一篇: 牛客网国庆集训派对Day3 H-Travel(计数问题)
下一篇: hdu5821 Ball(贪心)
小衣同学
博客等级 码龄9年 1444粉丝 995原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小衣同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址