nowcoder 207G - Coding Contest - [最小费用最大流]
Posted dilthey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nowcoder 207G - Coding Contest - [最小费用最大流]相关的知识,希望对你有一定的参考价值。
题目链接:https://www.nowcoder.com/acm/contest/207/G
时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there would be M directed paths linking these blocks. The i-th path goes from the ui-th block to the vi-th block. Your task is to solve the lunch issue. According to the arrangement, there are si competitors in the i-th block. Limited to the size of table, bi bags of lunch including breads, sausages and milk would be put in the i-th block. As a result, some competitors need to move to another block to access lunch. However, the playground is temporary, as a result there would be so many wires on the path.
For the i-th path, the wires have been stabilized at ?rst and the ?rst competitor who walker through it would not break the wires. Since then, however, when a person go through the i?th path, there is a chance of pi to touch the wires and a?ect the whole networks. Moreover, to protect these wires, no more than ci competitors are allowed to walk through the i-th path.
Now you need to ?nd a way for all competitors to get their lunch, and minimize the possibility of network crashing.
输入描述:
The ?rst line of input contains an integer t which is the number of test cases. Then t test cases follow.
For each test case, the ?rst line consists of two integers N (N ≤ 100) and M (M ≤ 5000). Each of the next N lines contains two integers si and bi (si,bi ≤ 200).
Each of the next M lines contains three integers ui,vi and ci(ci ≤ 100) and a ?oat-point number pi(0 < pi < 1). It is guaranteed that there is at least one way to let every competitor has lunch.
输出描述:
For each turn of each case, output the minimum possibility that the networks would break down. Round it to 2 digits.
示例1
输入
1
4 4
2 0
0 3
3 0
0 3
1 2 5 0.5
3 2 5 0.5
1 4 5 0.5
3 4 5 0.5
输出
0.50
题意:
题目的灵感估计来源于现场赛发餐包的操作……
现在赛场划分成了 $N$ 个不相交区域,共有 $M$ 条有向路连接两个区域,
对于每个区域,给出 $s[i],b[i]$ 代表区域内有 $s[i]$ 个人,$b[i]$ 个餐包,一旦某人在本区域内拿不到餐包,就会前往其他区域获取餐包,
而众所周知,赛场上的路上是有很多电线的,一不小心就会踢到电线,所以现在每条路上都存在这一些电线,
现在已知,一旦某个选手走过第 $i$ 条有向边,就有 $p[i]$ 的概率踢到电线,进而影响整个电网,不过经过该路径的第一个人是必然不会踢到电线的,同时对于第 $i$ 条边,限制最多 $c[i]$ 个人走过。
现在,求整个电网被影响的最小概率。
题解:
首先,我们考虑既然将来还要深入学习数学相关知识,概率和期望这一块是怎么样都跑不掉的,所以还不如现在趁机好好巩固一下概率论的基础知识……
考虑每个人踢到电线的概率是相互独立的,我们将某次某个人经过某条边称作一次实验,
若每次实验踢到电线事件发生的概率相同,则 $n$ 个人踢到电线 $k$ 次的概率服从二项分布,众所周知二项分布的公式为
$Pleft( {X = k} ight) = C_n^k p^k left( {1 - p} ight)^{n - k}$
其中 $p$ 即为一次实验中发生踢到电线事件的概率;
而发生踢到电线这一事件发生 $1,2,3,cdots$ 次均会影响电网,所以总共进行 $n$ 次独立实验后,电网被影响的概率为
$sumlimits_{k = 1}^n {Pleft( {X = k} ight)} = 1 - Pleft( {X = 0} ight)$
易知
$Pleft( {X = 0} ight) = left( {1 - p} ight)^n$
但是我们知道,电网被影响的概率为
$Pleft( {X = 1,2, cdots ,n} ight) = 1 - left( {1 - p} ight)^n$
当然,本题中,每次实验踢电线事件发生概率不一定相同,但是概率的计算方法依然符合上式:
$P = 1 - prodlimits_{i = 1}^n {left( {1 - pleft[ i ight]} ight)}$
也就是说,
以上是关于nowcoder 207G - Coding Contest - [最小费用最大流]的主要内容,如果未能解决你的问题,请参考以下文章