標籤:基礎知識 ora its 來源 through issue 怎麼 one acm
題目連結: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$ 次的機率服從二項分布,眾所周知二項分布的公式為
$P\left( {X = k} \right) = C_n^k p^k \left( {1 - p} \right)^{n - k}$
其中 $p$ 即為一次實驗中發生踢到電線事件的機率;
而發生踢到電線這一事件發生 $1,2,3,\cdots$ 次均會影響電網,所以總共進行 $n$ 次獨立實驗後,電網被影響的機率為
$\sum\limits_{k = 1}^n {P\left( {X = k} \right)} = 1 - P\left( {X = 0} \right)$
易知
$P\left( {X = 0} \right) = \left( {1 - p} \right)^n$
但是我們知道,電網被影響的機率為
$P\left( {X = 1,2, \cdots ,n} \right) = 1 - \left( {1 - p} \right)^n$
當然,本題中,每次實驗踢電線事件發生機率不一定相同,但是機率的計算方法依然符合上式:
$P = 1 - \prod\limits_{i = 1}^n {\left( {1 - p\left[ i \right]} \right)}$
也就是說,
nowcoder 207G - Coding Contest - [最小費用最大流]