【BZOJ1001】[BeiJing2006]狼抓兔子

挺簡單一個題,最小割模板

我的感覺就是可能建圖的時候會比較麻煩吧,畢竟三個方向。

#include <cctype>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>#define debug(x) std::cout << #x << " = " << x << std::endl;#define __OPTIMIZED__INPUT__
int nextInt()
{int num = 0;char c;bool flag = false;while ((c = std::getchar()) == ' ' || c == '\r' || c == '\n' || c == '\t');if (c == '-')flag = true;elsenum = c - 48;while (std::isdigit(c = std::getchar()))num = num * 10 + c - 48;return (flag ? - 1 : 1) * num;
}struct
{int to;int nex;int v;
} e[600001];
int head[600001];
int h[600001], q[600001];
int ans, n, m;void Insert(const int u, const int v, const int w)
{static int tot = 0;tot++;e[tot].to = v;e[tot].v = w;e[tot].nex = head[u];head[u] = tot;
}bool bfs()
{int now, i;std::memset(h, 0xff, sizeof h);int t = 0;int w = 1;q[t] = 1;h[1] = 0;while (t < w){now = q[t];t++;i = head[now];for (int i = head[now]; i; i = e[i].nex)if (e[i].v && h[e[i].to] < 0){q[w++] = e[i].to;h[e[i].to] = h[now] + 1;}}if (h[n * m] == -1)return 0;return 1;
}int dfs(const int x, const int f)
{if (x == n * m)return f;int w, used = 0;for (int i = head[x]; i; i = e[i].nex)if (e[i].v && h[e[i].to] == h[x] + 1){w = dfs(e[i].to, std::min(w, e[i].v));e[i].v -= w;e[i + 1].v += w;used += w;if (used == f)return f;}if (!used)h[x] = -1;
//  debug(used);return used;
}void Dinic()
{while (bfs())ans += dfs(1, INT_MAX);
}int main(int argc, char ** argv)
{n = nextInt();m = nextInt();int x;for (int i = 1; i <= n; i++)for (int j = 1; j < m; j++){x = nextInt();Insert(m * (i - 1) + j, m * (i - 1) + j + 1, x);Insert(m * (i - 1) + j + 1, m * (i - 1) + j, x);}for (int i = 1; i < n; i++)for (int j = 1; j <= m; j++){x = nextInt();Insert(m * (i - 1) + j, m * i + j, x);Insert(m * i + j, m * (i - 1) + j, x);}for (int i = 1; i < n; i++)for (int j = 1; j < m; j++){x = nextInt();Insert(m * (i - 1) + j, m * i + j + 1, x);Insert(m * i + j + 1, m * (i - 1) + j, x);}Dinic();std::cout << ans/* << std::endl*/;
#ifdef __NOTEPADPPstd::cin.get();std::cin.get();
#endifreturn 0;
}

轉載于:https://www.cnblogs.com/edwardtsui/p/6782858.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/396475.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/396475.shtml
英文地址,請注明出處:http://en.pswp.cn/news/396475.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

管理活動目錄域服務實訓_管理學院學生黨支部開展實踐教育基地服務活動

紅星E校有態度 有溫度 可關注為進一步加強黨的建設&#xff0c;深化管理學院學生黨支部與實踐基地的互動性&#xff0c;2020年9月11至12日&#xff0c;管理學院學生黨支部協助白鶴村村委實踐基地完成第七次人口普查相關工作&#xff0c;共計6名預備黨員參與。工作開始前的培訓會…

mysql 漢編碼 的選_peewee連接mysql漢語言數據編碼_mysql

peewee連接mysql中文數據編碼系統是win7 x64python 2.7.6的site.py里面編碼設定為 utf-8py文件首行指定 #coding:utf-8mysql 5.5.38安裝時指定代碼為utf-8peewee的連接數據庫代碼為&#xff1a;db MySQLDatabase(host 127.0.0.1, user root, passwd 1, database mz, chars…

配置windows失敗,還原更新,請勿關機

最近給同事裝系統&#xff0c;偶爾會出現如下問題&#xff1a; 如果是這種情況&#xff0c;只能耐心等待了&#xff0c;因為關機也沒用&#xff01; 轉載于:https://www.cnblogs.com/lijy/p/5327844.html

使用Express和MongoDB構建簡單的CRUD應用程序

by Zell Liew由Zell Liew 使用Express和MongoDB構建簡單的CRUD應用程序 (Building a Simple CRUD Application with Express and MongoDB) For a long time, I didn’t dare venture into back end development. I felt intimidated because of my lack of an academic backgr…

python元類的使用_python中元類用法實例

本文實例講述了python中元類用法&#xff0c;分享給大家供大家參考。具體方法分析如下&#xff1a;1.元類(metaclass)是用來創建類的類2.type(object):返回一個對象的類型&#xff0c;與object.__class__的值相同&#xff0c;type(name,bases,dict):創建一個新的type類型&#…

使用uicollectionView時需要注意的問題

1.UICollectionView使用流水布局——UICollectionViewFlowLayout時&#xff0c;需要滿足條件&#xff1a; 每個item(即cell)的大小是一樣的&#xff0c;不僅是寬度&#xff0c;還有高度。這樣&#xff0c;當collectionview的寬度發生變化時&#xff0c;item能將其動態填充。ite…

hiveql函數筆記(二)

1、數據查詢 //提高聚合的性能 SET hive.map.aggrtrue; SELECT count(*),avg(salary) FROM employees; //木匾不允許在一個查詢語句中使用多于一個的函數&#xff08;DISTINCT。。。&#xff09;表達式 SELECT count(DISTINCT symbol) FROM stocks; 表生成函數&#xff1a; exp…

jQuery 常用的方法

<!DOCTYPE html><html lang"en"><head> <meta charset"utf-8"/> <title>品牌列表案例</title> <script src"js/jquery-2.1.1.min.js" rel"script"></script> <script…

swift 從手機選照片_19元起!定制專屬手機殼!還可免費打印照片...

△劇透&#xff1a;文末有福利現在的年輕人體內涌動的都是追求有趣有特色的靈魂希望自己是這條gai最獨一無二的仔撞衫撞包撞手機殼可以說是當代年輕人三大時尚忌諱尤其是手機殼極為重要畢竟換殼≈換機只需要幾十元買新殼就可以擁有換新機般的儀式感不過作為手機殼老手都知道在某…

新手也能學會本地調試微信,natapp 官網映射

本地調試微信的新手指引~ 照著配置&#xff0c;一定可以配置成功&#xff0c;實現本地調試微信&#xff0c;公司好幾個同事按照我寫的步驟&#xff0c;都獨立配成功了。 1.首選在natapp注冊一個賬號&#xff0c;申請免費隧道或者購買隧道&#xff0c;我買了一個月9元的付費隧道…

在JavaScript中反轉字符串的三種方法

This article is based on Free Code Camp Basic Algorithm Scripting “Reverse a String”本文基于Free Code Camp基本算法腳本“ Reverse a String ” Reversing a string is one of the most frequently asked JavaScript question in the technical round of interview. …

c實現三角形角度大于一個值_初中數學三角形知識點小結

▊ 三角形兩邊定理&#xff1a;三角形兩邊的和大于第三邊。推論&#xff1a;三角形兩邊的差小于第三邊。▊ 三角形中位線定理三角形的中位線平行于第三邊&#xff0c;并且等于它的一半。▊ 三角形的重心三角形的重心到頂點的距離是它到對邊中點距離的2倍。在三角形中&#x…

【Spring】使用Spring和AMQP發送接收消息(下)

為什么80%的碼農都做不了架構師&#xff1f;>>> 上篇講了RabbitMQ連接工廠的作用是用來創建RabbitMQ的連接&#xff0c;本篇就來講講RabbitMQ的發送消息。通過RabbitMQ發送消息最簡單的方式就是將connectionFactory Bean注入到服務層類中&#xff0c;并使用它創建C…

微軟u盤安裝工具_使用微軟Winget工具安裝軟件教程

對于系統管理員來說&#xff0c;一款好用的軟件包管理工具可以大大提高安裝、部署、管理軟件的效率。可之前只有 MscOS 和 Linux 官方才有軟件包管理工具&#xff0c;微軟官方現在終于為Windows系統發布了一款名為Winget的軟件包管理工具&#xff0c;MS酋長下面就來為大家演示一…

ZOJ2930 The Worst Schedule(最小割)

題目大概說有n個任務&#xff0c;每個任務可以提前或推遲&#xff0c;提前或推遲各有一定的費用&#xff0c;有的任務一旦推遲另一個任務也必須推遲&#xff0c;問怎么安排任務使花費最少&#xff0c;且最少花費的條件下提前的任務數最多能多少。 問題就是要把各個任務分成兩個…

為什么要free釋放內存_為什么在Free Code Camp上列出一份工作要花1,000美元?

為什么要free釋放內存by Michael D. Johnson邁克爾約翰遜(Michael D.Johnson) 為什么在Free Code Camp上列出一份工作要花1,000美元&#xff1f; (Why does it cost $1,000 to list a job on Free Code Camp?) I’ve recently spoken with employers looking for JavaScript …

python訪問注冊表_讀取注冊表的Python代碼

如果“Uninstall”中有超過1024個子鍵怎么辦&#xff1f;Use _winreg.QueryInfoKey(key)Python2:import errno, os, _winregproc_arch os.environ[PROCESSOR_ARCHITECTURE].lower()proc_arch64 os.environ[PROCESSOR_ARCHITEW6432].lower()if proc_arch x86 and not proc_ar…

ios 動畫 隱藏tabbar_UITabBarViewController 的底部 tabBar 隱藏

iOS pushViewController 時候隱藏 TabBar 的可以用interfaceUIViewController (UINavigationControllerItem)property(nonatomic,readonly,strong)UINavigationItem*navigationItem;// Created on-demand so that a view controller may customize its navigation appearance.p…

JS進階之---函數,立即執行函數

一、函數 函數聲明、函數表達式、匿名函數 函數聲明&#xff1a;使用function關鍵字聲明一個函數&#xff0c;再指定一個函數名&#xff0c;叫函數聲明。function name () { … } 函數表達式&#xff1a;使用function關鍵字聲明一個函數&#xff0c;但未給函數命名&#xff0c;…

主線程中有多個handler的情況

https://www.cnblogs.com/transmuse/archive/2011/05/16/2048073.html轉載于:https://www.cnblogs.com/genggeng/p/9806415.html