[POJ 3728]The merchant】的更多相关文章

The merchant Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4556   Accepted: 1576 Description There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and w…
Description There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and wants to earn as much money as possible in each path. When he move along a path, he can choose on…
[题目链接] http://poj.org/problem?id=3728 [题目大意] 给出一棵树,每个点上都可以交易货物,现在给出某货物在不同点的价格, 问从u到v的路程中,只允许做一次买入和一次卖出,最多能得到多少钱. [题解] 我们维护一个up表示,x与父节点的连线中, 最大值在靠近父节点的位置时最小值与最大值的最大差值 dw表示,x与父节点的连线中,最小值在靠近父节点的位置时最小值与最大值的最大差值 Min和Max分别表示x到父节点中的最大值和最小值 对于询问x到y的答案,我们发现以L…
The merchant Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5055   Accepted: 1740 Description There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and w…
Description There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and wants to earn as much money as possible in each path. When he move along a path, he can choose on…
The merchant Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 1   Accepted Submission(s) : 1 Problem Description There are N cities in a country, and there is one and only one simple path between…
题目: zdf给出的题目翻译: 从前有一个富饶的国度,在这里人们可以进行自由的交易.这个国度形成一个n个点的无向图,每个点表示一个城市,并且有一个权值w[i],表示这个城市出售或收购这个权值的物品.又到了一年一次团圆的日子,所有外出打工的人都急忙赶着回家.现在有m个人,给出每个人的工作地点和家的编号,让你求出每个人在回家的路上通过倒卖物品获得的最大收益,因为要急忙赶着回家,所以他们一定会选择最短的路程,并且只进行一次倒卖(即最多买一次.卖一次). 分析: 与倍增求lca相似,额外记录四个值: d…
题目:https://vjudge.net/contest/323605#problem/E 题意:一棵n个点的树,然后有m个查询,每次查询找(u->v)路径上的两个数,a[i],a[j],(i<j)a[j]-a[i]的最大值,j必须是u->v路径上出现的比i晚 思路:首先我们路径肯定是确定只有一条的,然后我们怎么找出那条路径呢,我们可以求LCA,求出u->LCA(u,v)   LCA(u,v)->v  ,这样我们就能把路径给确定出来 然后我们先简化问题,如果是一个序列,我们…
http://poj.org/problem?id=3728 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5068   Accepted: 1744 Description There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chose…
题意:给定一个N个节点的树,1<=N<=50000 每个节点都有一个权值,代表商品在这个节点的价格.商人从某个节点a移动到节点b,且只能购买并出售一次商品,问最多可以产生多大的利润. 思路:路径压缩,得到每个点到当前根的信息,然后更新即可. 有可以用倍增做. 很久前抄的代码. #include<cstdio> #define min(a,b) (a<b?a:b) #define max(a,b) (a>b?a:b) #define swap(a,b) (a^=b,b^=…