1. 程式人生 > >最小費用流判負環消圈演算法(poj2175)

最小費用流判負環消圈演算法(poj2175)

The City has a number of municipal buildings and a number of fallout shelters that were build specially to hide municipal workers in case of a nuclear war. Each fallout shelter has a limited capacity in terms of a number of people it can accommodate, and there's almost no excess capacity in The City's fallout shelters. Ideally, all workers from a given municipal building shall run to the nearest fallout shelter. However, this will lead to overcrowding of some fallout shelters, while others will be half-empty at the same time. 

To address this problem, The City Council has developed a special evacuation plan. Instead of assigning every worker to a fallout shelter individually (which will be a huge amount of information to keep), they allocated fallout shelters to municipal buildings, listing the number of workers from every building that shall use a given fallout shelter, and left the task of individual assignments to the buildings' management. The plan takes into account a number of workers in every building - all of them are assigned to fallout shelters, and a limited capacity of each fallout shelter - every fallout shelter is assigned to no more workers then it can accommodate, though some fallout shelters may be not used completely. 

The City Council claims that their evacuation plan is optimal, in the sense that it minimizes the total time to reach fallout shelters for all workers in The City, which is the sum for all workers of the time to go from the worker's municipal building to the fallout shelter assigned to this worker. 

The City Mayor, well known for his constant confrontation with The City Council, does not buy their claim and hires you as an independent consultant to verify the evacuation plan. Your task is to either ensure that the evacuation plan is indeed optimal, or to prove otherwise by presenting another evacuation plan with the smaller total time to reach fallout shelters, thus clearly exposing The City Council's incompetence. 

During initial requirements gathering phase of your project, you have found that The City is represented by a rectangular grid. The location of municipal buildings and fallout shelters is specified by two integer numbers and the time to go between municipal building at the location (Xi, Yi) and the fallout shelter at the location (Pj, Qj) is Di,j
 = |Xi - Pj| + |Yi - Qj| + 1 minutes. 

相關推薦

費用演算法poj2175

The City has a number of municipal buildings and a number of fallout shelters that were build specially to hide municipal workers in case of a nuclear war

[Bzoj3232]地遊戲分數規劃+割/spfa

Description DZY家的後院有一塊地,由N行M列的方格組成,格子內種的菜有一定的價值,並且每一條單位長度的格線有一定的費用。 DZY喜歡在地裡散步。他總是從任意一個格點出發,沿著格線行走直到回到出發點,且在行走途中不允許與已走過的路線有任何相交或觸碰(出發點除外)。記這條

POJ - 2175 Evacuation Plan (費用)

sca eof mat 反向 front 發的 lin i++ 意義 題意:有N棟樓,每棟樓有\(val_i\)個人要避難,現在有M個避難所,每個避難所的容量為\(cap_i\),每個人從樓i到避難所j的話費是兩者的曼哈頓距離.現在給出解決方案,問這個解決方案是否是花費最小

【BZOJ】5120: [2017國家集訓隊測試]無限之-費用

傳送門:bzoj5120 題解 要求所有接頭相連,實際上就是將邊拆成入度和出度,要求滿流。 將每個點拆成五個點,分別表示上下左右和中心點。按橫縱座標和奇偶進行黑白染色,源點 S

【BZOJ2424】[HAOI2010]訂貨 費用

需求 bfs pop 容量 family light 成本 pri || 【BZOJ2424】[HAOI2010]訂貨 Description 某公司估計市場在第i個月對某產品的需求量為Ui,已知在第i月該產品的訂貨單價為di,上個月月底未銷完的單位產品要付存貯費用

HDU 3435A new Graph Game網絡費用

new ext 感覺 span hdu string.h return pri cpp 題目地址:HDU 3435 這題剛上來一看,感覺毫無頭緒。。再細致想想。。發現跟我做的前兩道費用流的題是差點兒相同的。能夠往那上面轉換。 建圖基本差點兒相同。僅僅只是這裏是無向圖。建

[轉]從入門到精通: 費用的“zkw算法”

值範圍 add turn 所有 運行時 static col sap 上下 >>>> 原文地址:最小費用流的“zkw算法” <<<< 1. 網絡流的一些基本概念 很多同學建立過網絡流模型做題目, 也

UVa 1658,Admiral (拆點+限制費用)

{} name 最小 ssi set dex 一個點 cost line 題目鏈接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_

LibreOJ #102. 費用

費用流 lib bsp targe tdi 最小費用流 pro main min 二次聯通門 : LibreOJ #102. 最小費用流 /* LibreOJ #102. 最小費用流 Spfa跑花費 記錄路徑 倒

【HDOJ6118】度度熊的交易計劃費用

const 費用流 sign else read true head 最大的 自動調整 題意: 度度熊參與了喵哈哈村的商業大會,但是這次商業大會遇到了一個難題:喵哈哈村以及周圍的村莊可以看做是一共由n個片區,m條公路組成的地區。由於生產能力的區別,第i個片區能夠花費a[i]

費用hdu 61182017百度之星初賽B 1005 度度熊的交易計劃

ios rsh des pty rank tom mis 註意 pan 度度熊的交易計劃 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su

HOJ - 2543費用

memset max class cap 個數 hoj else hit clu 題目鏈接:http://acm.hit.edu.cn/hoj/problem/view?id=2543 這個題目挺有意思。 自己扣了一會兒,發現圖挺好建,就把(u,v,f,w) 拆成(u,v,

費用模板

queue || bfs () const mes 最大流 amp -a 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include

bzoj 1877 費用

using fine edge ont scanf pre clu queue bits 思路:挺裸的費用流,拆拆點就好啦。 #include<bits/stdc++.h> #define LL long long #define fi first

hdu 4067 Random Maze費用

In the game “A Chinese Ghost Story”, there are many random mazes which have some characteristic: 1.There is only one entrance and

POJ 3422 - Kaka's Matrix Travels費用

題目連結 https://cn.vjudge.net/problem/POJ-3422 【題意】 給出一個N*N的矩陣,然後從左上角走到右下角,每次走只能是往下或者往右走,走一次就將這個位置上的數字加到sum和中,然後這個位置的數字置為0。從左上到右下走K次,問最大和。 【思路】 最

UVA 1658 - 海軍上將 費用+拆點

題目連結:https://vjudge.net/problem/UVA-1658 思路:拆點+最小費用流。這裡的拆點法是解決網路流限制點的常用辦法,因為如果直接刪除點,會影響很多邊,所以對每個非源點匯點的節點,將其拆成兩個節點,一個真節點,一個假節點,並在節點中建邊,容量為1,如果這條邊滿載了,

HDU - 3667 Transportation[費用 拆邊]

HDU - 3667  Transportation 題意:給一張圖,第i條邊有的代價為 , flow指的是當前這條邊的流量,求從頂點1出發,到達頂點N的最小代價 思路: 費用流要求每條邊的費用是單價費用,而這題是單價的平方. 但這題容量C尤其的小 可以發現,

HDU1533 Going Home [費用]

HDU1533 Going Home 思路: 保證最大流:能保證每個人對應一個房子 保證最小費用流:MCMF #include <cstdio> #include <cstring> #include <queue> #includ

hdu5988費用浮點

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=5988 思路:求網路最小破壞可能,就是求最大不破壞的可能,再加上一個負號又變成了求最小費用流,對於乘法加上一個對數就變成了加法,需要注意的是對於浮點數要加上eps。 #pragma GCC o