題解/算法 {6243. 到达首都的最少油耗}

oi-link

Solution

Actually, the path of a car is not unique (go forward to 0 0 0), although this is not clear from the implication of this problem, but there is also no stipulation limits on the path, so you can imagined that the path is arbitrary (the direction is arbitrary, stop or move is arbitrary). for example

0
1
2
3 
4 5

for 4 , 5 4, 5 4,5, if using two cars, then the cost is 4 + 4 4 + 4 4+4; but if the car of 4 4 4 turn on 3 3 3 and then to take 5 5 5, it costs 1 + 1 + 1 + 3 1 + 1 + 1 + 3 1+1+1+3, it is better.

But, the latter is also not the best. (you can let the car of 4 4 4 stop at 3 3 3, and then 5 5 5 uses its own car to 3 3 3, then 5 5 5 get off and use the car of 4 4 4 together)

Due to the least distance between a a a and 0 0 0 is the simple-path, so, the path of the car a a a may be this simple-path, but the path of a a a must be this simple-path.

For a number a a a, the size of the subtree which take a a a as its root is 1 + k 1 + k 1+k ( k k k is the count of its sons).
Supposing that these 1 + k 1+k 1+k are now at a a a, our goal is to take these points to f a fa fa (the father of a a a), this will cost ( 1 + k ) / L (1 + k) / L (1+k)/L (upper round) cars.
So, the answer is the sum of all this number of all points but 0 0 0.

Code

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值