UVA 10746 Crime Wave – The Sequel(費用流)
ProblemG
CrimeWave – The Sequel
Input: StandardInput
Output: StandardOutput
TimeLimit: 2 Seconds
n bankshave been robbed this fine day. m (greater than orequal to n) police cruisers are on duty at variouslocations in the city. n of the cruisers should bedispatched, one to each of the banks, so as to minimize the averagetime of arrival at the n banks.
Input
Theinput file contains several sets of inputs. The description of eachset is given below:
Thefirst line of input contains 0 < n <= m <=20. n lines follow, each containing m positivereal numbers: the travel time for cruiser m to reachbank n.
Inputis terminated by a case where m=n=0. This case should notbe processed.
Output
Foreach set of input output a single number: the minimum average traveltime, accurate to 2 fractional digits.
SampleInput Outputfor Sample Input
3 4
10.0 23.0 30.0 40.0
5.0 20.0 10.0 60.0
18.0 20.0 20.0 30.0
00
13.33
Problemsetter: GordonCormack, EPS
題意:
有m個警察,派n個警察到n個銀行,給出每個警察到各銀行的時間,求最小的平均時間。
分析:
平均乘上n就是總時間,也就是要最小化總時間,那麼用費用流就可以解決問題。各銀行向每個警察連邊,容量1,費用為時間;增加源點,源點向各銀行連邊,容量1,費用0;增加匯點,警察向匯點連邊,容量1,費用0。在圖中跑費用流就行。
這題最惡心的地方在於保留小數,結果加上eps再輸出。這裡涉及到保留小數方法,是用傳統的四捨五入還是用銀行家捨入?都不知道以後涉及到小數的輸出要怎麼搞了,這種東西就該spj啊。
/*
*
* Author : fcbruce
*
* Date : 2014-09-05 20:37:26
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include