题解/算法 {361. 观光奶牛}

题解/算法 {361. 观光奶牛}

@LINK: https://www.acwing.com/problem/content/description/363/;

@DELI;

For the answer-loop, let its values on points be A 1 , A 2 , . . . , A n A1, A2, ..., An A1,A2,...,An, the weights on edges be E 1 , E 2 , . . . , E n E1, E2, ..., En E1,E2,...,En, then its worth is A 1 + . . . + A n E 1 + . . . + E n = k \frac{A1 +... +An}{E1 + ... +En} = k E1+...+EnA1+...+An=k

If we set a function C ( x ) C(x) C(x) denotes that whether there exists a loops such that its worth ≥ x \geq x x, then we have C ( ≥ k ) = t r u e C( \geq k) = true C(k)=true, C ( < k ) = f a l s e C( < k) = false C(<k)=false (satisfying the Dichotomy-Method)

If C ( x ) = t r u e C(x) = true C(x)=true, it shows that there is a loop A 1 + . . . + A i E 1 + . . . + E i ≥ k \frac{A1 +... +Ai}{E1 + ... +Ei} \geq k E1+...+EiA1+...+Aik
A 1 + . . . + A i ≥ k ∗ E 1 + . . . + k ∗ E i A1 + ... + Ai \geq k * E1 + ... + k * Ei A1+...+AikE1+...+kEi
( A 1 − k ∗ E 1 ) + . . . + ( A i − k ∗ E i ) ≥ 0 (A1 - k * E1) + ... + (Ai - k * Ei) \geq 0 (A1kE1)+...+(AikEi)0

When we at the process C ( x ) C(x) C(x), we can construct a graph G G G whose edge-weight of a → b a \to b ab equals A [ a ] − x ∗ E [ a → b ] A[ a] - x * E[ a \to b] A[a]xE[ab]
If C ( x ) = t r u e C(x) = true C(x)=true, then that is equivalent to G G G exits a Positive-Loop;
This can be done by SPFA-Check-Loop for calculating the longest-path (not shortest), set all Distances be 0 0 0 initially.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值