1. 程式人生 > >[BZOJ]4842: [Neerc2016]Delight for a Cat 1061: [Noi2008]志願者招募 費用流 線性規劃

[BZOJ]4842: [Neerc2016]Delight for a Cat 1061: [Noi2008]志願者招募 費用流 線性規劃

題解:

把這兩道題目放在一起寫,因為做法是一樣的。
兩題都是經典的線性規劃問題,但同時也都可以用費用流解決。
以志願者招募這題為例,首先設第 i i 類志願者有 x i

x_i 人。
那麼根據樣例可以列出不等式:
{ x 1
2 x 1
+ x 2 3
x 2 + x 3 4 \begin{cases} x_1\geq2\\ x_1+x_2\geq3\\ x_2+x_3\geq4 \end{cases}

我們的目標是使 2 x 1 + 5 x 2 + 2 x 3 2x_1+5x_2+2x_3 最小。
把不等式改寫成等式:
{ x 1 = 2 + y 1 x 1 + x 2 = 3 + y 2 x 2 + x 3 = 4 + y 3 \begin{cases} x_1=2+y_1\\ x_1+x_2=3+y_2\\ x_2+x_3=4+y_3 \end{cases}
然後再差分一下,同時保留第一個原式和最後一個不等式的符號取反,得:
{ x 1 = y 1 + 2 x 2 = y 1 + y 2 + 1 x 1 + x 3 = y 2 + y 3 + 1 x 2 x 3 = y 3 4 \begin{cases} x_1=y_1+2\\ x_2=-y_1+y_2+1\\ -x_1+x_3=-y_2+y_3+1\\ -x_2-x_3=-y_3-4 \end{cases}
再讓全部符號變成正號,移項得:
{ x 1 = y 1 + 2 x 2 + y 1 = y 2 + 1 x 3 + y 2 = x 1 + y 3 + 1 y 3 + 4 = x 2 + x 3 \begin{cases} x_1=y_1+2\\ x_2+y_1=y_2+1\\ x_3+y_2=x_1+y_3+1\\ y_3+4=x_2+x_3 \end{cases}
然後可以發現每個未知量都出現且僅出現了兩次(這個由題目的性質決定),而且一次是在等號左邊一次在右邊,然後可以開始建圖了,把每個等式看做是一個點,右邊看做是流入量,左邊看做是流出量,由於滿足流量平衡,所以滿足等式。因此流量的含義就是每個數的大小,如果是未知數,那麼在它左邊出現的式子向右邊出現的式子連一條流量為 i n f inf ,費用為 C i C_i 的邊,含義是 x i x_i 可以取無限大,每取一個有代價。如果是常數,就由源點補充或流向匯點。
跑費用流就可以了。

4842程式碼:

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=1010;
const LL inf=(1LL<<50);
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x*f;
}
LL ans=0;
int lx[Maxn],rx[Maxn],ly[Maxn],ry[Maxn],lz[Maxn],rz
            
           

相關推薦

[BZOJ]4842: [Neerc2016]Delight for a Cat 1061: [Noi2008]志願者招募 費用 線性規劃

題解: 把這兩道題目放在一起寫,因為做法是一樣的。 兩題都是經典的線性規劃問題,但同時也都可以用費用流解決。 以志願者招募這題為例,首先設第 i

bzoj 4842: [Neerc2016]Delight for a Cat

cst des inf rip 小朋友 clas 最大 一行 return Description ls是一個特別墮落的小朋友,對於n個連續的小時,他將要麽睡覺要麽打隔膜,一個小時內他不能既睡覺也打隔膜 ,因此一個小時內他只能選擇睡覺或者打隔膜,當然他也必須選擇睡覺

Codeforces Gym 101190 NEERC 16 .D Delight for a Cat (上下界的費用

至少 light bool clu back 技術分享 || 方案 思路 ls是一個特別墮落的小朋友,對於n個連續的小時,他將要麽睡覺要麽打隔膜,一個小時內他不能既睡覺也打隔膜 ,因此一個小時內他只能選擇睡覺或者打隔膜,當然他也必須選擇睡覺或打隔膜,對於每一個小時,他選擇

BZOJ 10611061: [Noi2008]志願者招募線性規劃與網路)**

1061: [Noi2008]志願者招募 Description   申奧成功後,布布經過不懈努力,終於成為奧組委下屬公司人力資源部門的主管。布布剛上任就遇到了一個難 題:為即將啟動的奧運新專案招募一批短期志願者。經過估算,這個專案需要N 天才能完成,其中第i 天至少需要 Ai 個人。 布布通過了解得知

bzoj 1061 [Noi2008]志願者招募 單純形演算法

Description   申奧成功後,布布經過不懈努力,終於成為奧組委下屬公司人力資源部門的主管。布布剛上任就遇到了一個難 題:為即將啟動的奧運新專案招募一批短期志願者。經過估算,這個專案需要N

BZOJ 1061 [Noi2008]志願者招募 線性規劃

題意:連結 方法:線性規劃 解析: 不妨對樣例加以闡釋 3 3 2 3 4 1 2 2 2 3 5 3 3 2 不妨設Xi代表第i種志願者選Xi個人 那麼顯然,這題的限制為 X1>

BZOJ 1061】 [Noi2008]志願者招募

1061: [Noi2008]志願者招募 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 2066  Solved: 1282 [Submit][Status] Description 申奧成功後,布布經過不懈努力,終於

Search for a Range

new sorted param for art careful span get with O(logN) This question turns to find the first and last element of the target in a sorted

[leetcode-34-Search for a Range]

star earch tco leet ger ive sort size div Given an array of integers sorted in ascending order, find the starting and ending position of

java.sql.SQLTimeoutException: Timeout after 30001ms of waiting for a connection.

jdbc java 連接池HikariCP連接池出錯:java.sql.SQLTimeoutException: Timeout after 30001ms of waiting for a connection.出現這個問題的原因是 有的函數在用完connection的時候,沒有及時close,導致連接池

[Leetcode] search for a range 尋找範圍

earch exit 查找 run grand order pan leetcode [] Given a sorted array of integers, find the starting and ending position of a given target v

Search for a Range問題

rgba 找到 lang 分法 ria http 並且 plan bin Search for a Range問題leetcodejava二分查找 1. 問題描述 Given an array of integers sorted in ascending or

34. Search for a Range

sea int mod style boolean color pan target -1 public class Solution { public int[] searchRange(int[] nums, int target) {

WAITED TOO LONG FOR A ROW CACHE ENQUEUE LOCK!的分析

waited too long for a row cache enqueue lock!的分析今天我的數據庫hang住了,查看告警日誌提示WAITED TOO LONG FOR A ROW CACHE ENQUEUE LOCK! pid=31AIX 5.3 是一個RAC環境,10.2.0.4由於問題一致,我

ENGINEERING: YOUR CHANCE FOR A HIGH PAYING ENTRY LEVEL JOBS?

HIGH PAYING ENTRY LEVEL JOBS High paying entry level jobs are always in demand, and we believe there’s no need to elaborate on this. Con

[LeetCode] Search for a Range

ted runt found vector class arch algorithm com pty Given an array of integers sorted in ascending order, find the starting and ending po

Suggestion in searching for a job in NZ

his search achieved n-n minutes user jea log youtube https://ivangrigoryev.com/en/silver-fern-visa-or-how-i-got-work-in-new-zealand-in-te

LeetCode-34. Search for a Range

改變 必須 條件篩選 col sea 二分法 tro 例子 spa 一、問題描述   給定一個升序排列的數組nums,和一個目標數target,找出nums中target的索引範圍。   例子:給定數組為{5, 7, 7, 8, 8, 10},target=8。返回{3,4

Where is the SPFILE for a PDB database ?

pdb spfile pdf pfile - Where is the SPFILE for a PDB database ? PDBs do not have an init.ora file or SPFILE, only the root‘s CDB has one. Parameters f

netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in

netstat#netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’ netstat -n|grep ^tcp | awk ‘{++S[$NF]} END {for(a in S) print a, S[a]}’LAST_