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

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…
题目大意: 给你一棵n个结点的带权树,有q组询问,问你从u到v的路径上最大值与最小值的差(最大值在最小值后面). 思路: 首先考虑路径上合并两个子路径u->t和t->v时的情况. 假设我们已经知道了两个路径的最大值max,最小值min,以及路径上最大值与最小值的差d(最大值在最小值后面), 那么我们最大值和最小值可以直接合并,d=max(d1,d2,max2-max1). 现在我们用倍增或者树链剖分维护这些东西,再跑一跑LCA即可. 然而我们发现往上跑和往下跑是不一样的,所以我们要维护两种差值…
传送门 比着题解写还错... 查了两个小时没查出来,心态爆炸啊 以后再查 ——代码(WA) #include <cstdio> #include <cstring> #include <iostream> #define N 2000001 #define Min(x, y) ((x) < (y) ? (x) : (y)) #define Max(x, y) ((x) > (y) ? (x) : (y)) #define swap(x, y) ((x) ^=…
题意简述:给定一个N个节点的树,1<=N<=50000 每个节点都有一个权值,代表商品在这个节点的价格.商人从某个节点a移动到节点b,且只能购买并出售一次商品,问最多可以产生多大的利润. 算法分析:显然任意两个城市之间的路径是唯一的,商人有方向地从起点移动到终点.询问这条路径上任意两点权值之差最大为多少,且要保证权值较大的节点在路径上位于权值较小的节点之后. 暴力的方法是显而易见的,只要找到两个点的深度最深的公共祖先,就等于找到了这条路径,之后沿着路径走一遍即可找到最大的利润,然而无法满足50…
给一棵点带权树,$q$次询问,问树上$x$到$y$路径上,两点权之差(后面的减去前面的)的最大值. 这个是在树链上找点,如果沿路径的最小值在最大值之前出现那肯定答案就是$maxx-minx$,但是反之就不好办了.. 方法一:在线倍增合并答案 先来看一个退化成链的情况:区间$ql,qr$内找$i<j$使$A_j-A_i$值最大怎么做. 这里尝试线段树解决.假设两个小区间合并答案的话,维护一个$dif_i$表示区间$i$上述答案. 那么合并区间答案时,要么答案出自左半区间,要么右半区间,要么跨中间,…
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…
传送门 Time Limit: 3000MS Memory Limit: 65536K 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.…
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…
ThoughtWorks笔试题之Merchant's Guide To The Galaxy解析 一.背景 在某网站上看到ThoughtWorks在武汉招人,待遇在本地还算不错,就投递了简历.第二天HR就打开电话,基本了解了一下情况(工作环境不错,男人妹子比例:1:1,双休,六险一金,满一年年假15天,病假8天,月薪1W--2W).然后立马收到一封:Coding Assignment的笔试题目.网上搜索了一下,发现这个公司还是挺大的,公司面试流程是出了名的繁杂和苛刻.据说有8轮:电话面试=>笔试…
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…