日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 3870】Catch the Theves(平面图转对偶图最短路,网络流最小割)

發布時間:2023/12/10 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 3870】Catch the Theves(平面图转对偶图最短路,网络流最小割) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

A group of thieves is approaching a museum in the country of zjsxzy,now they are in city A,and the museum is in city B,where keeps many broken legs of zjsxzy.Luckily,GW learned the conspiracy when he is watching stars and told it to zjsxzy.?
Zjsxzy decided to caught these thieves,and he let the police to do this,the police try to catch them on their way from A to B. Although the thieves might travel this way by more than one group, zjsxzy's excellent police has already gather the statistics that the cost needed on each road to guard it.?
Now ,zjsxzy's conutry can be described as a N*N matrix A,Aij indicates the city(i,j) have bidirectionals road to city(i+1,j) and city(i,j+1),gurad anyone of them costs Aij.?
Now give you the map,help zjsxzy to calculate the minimium cost.We assume thieves may travel in any way,and we will catch all passing thieves on a road if we guard it.?

Input

The first line is an integer T,followed by T test cases.?
In each test case,the first line contains a number N(1<N<=400).?
The following N lines,each line is N numbers,the jth number of the ith line is Aij.?
The city A is always located on (1,1) and the city B is always located on (n,n).?
Of course,the city (i,j) at the last row or last line won't have road to (i,j+1) or (i+1,j).?

Output

For each case,print a line with a number indicating the minimium cost to arrest all thieves.

Sample Input

1 3 10 5 5 6 6 20 4 7 9

Sample Output

18

Hint

The map is like this:

題目大意:

有一個n*n個點的格子。輸入n*n條邊,每個邊權代表(i,j) -> (i,j+1) 和 (i,j) -> (i+1,j)這兩條邊的邊權。求左上角到右下角的最小割、

解題報告:

? 直接轉對偶圖跑最短路。但是建圖的時候細節要注意一下。別建多了邊,寫錯了符號啥的。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 4e5 + 5; const int INF = 0x3f3f3f3f; struct Edge {int u,v,w;int ne; } e[MAX<<2]; int n; int head[MAX],tot; void add(int u,int v,int w) {//加雙向邊 e[++tot].v = v; e[tot].w = w; e[tot].ne = head[u]; head[u] = tot;e[++tot].v = u; e[tot].w = w; e[tot].ne = head[v]; head[v] = tot; } int ID(int x,int y) {return (x-1)*n + y; } int dis[MAX],vis[MAX]; struct Point {int pos,dis;Point(int pos=0,int dis=0):pos(pos),dis(dis){}bool operator < (const Point & b) const {return dis > b.dis;} }; int Dij(int st,int ed) {priority_queue<Point> pq;pq.push(Point(st,0));dis[st]=0;while(pq.size()) {Point cur = pq.top();pq.pop();if(vis[cur.pos]) continue;vis[cur.pos] = 1;for(int i = head[cur.pos]; ~i; i = e[i].ne) {int v = e[i].v;if(dis[v] > dis[cur.pos] + e[i].w) {dis[v] = dis[cur.pos] + e[i].w;pq.push(Point(v,dis[v]));}} }return dis[ed]; } int main() {int t;cin>>t;while(t--) {tot=0;scanf("%d",&n);for(int i = 0; i<=n*n + 2; i++) head[i] = -1,dis[i] = INF,vis[i] = 0;int st = n*n+1,ed=n*n+2;for(int x,i = 1; i<=n; i++) {for(int j = 1; j<=n; j++) {scanf("%d",&x);if( (i==1&&j!=n)|| (j==n&&i!=n) ) add(ID(i,j-(j==n)),ed,x);//和匯點 if( (i==n&&j!=n)|| (j==1&&i!=n) ) add(ID(i-(i==n),j),st,x);//和起點 if(i != 1 && i != n && j != n) add(ID(i-1,j),ID(i,j),x);//水平行之間if(j != 1 && j != n && i != n) add(ID(i,j-1),ID(i,j),x);//豎直列之間 }}printf("%d\n",Dij(st,ed)); }return 0 ; }

總結:

? 建圖的過程中雖然非常的顯而易見,但是還是出現了細節問題。比如剛開始直接寫的和源點和匯點的連邊,直接就是i==1||j==n代表和匯點相連,顯然這樣寫會有重邊,不光如此,第一行最右側那一條邊在連邊的時候,要注意是ID(i,j-1)和ed相連。

還有判斷水平邊(以水平邊為例)的時候,不僅要有i!=1&&i!=n,還要有j!=n這一個條件!總之別落下了判斷條件就行。

總結

以上是生活随笔為你收集整理的【HDU - 3870】Catch the Theves(平面图转对偶图最短路,网络流最小割)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久草超碰 | 成年人黄色大片 | 日韩欧美国产中文字幕 | 人人草人人爱 | 激情内射亚洲一区二区三区爱妻 | 欧美一区二区激情 | 91国产精品 | 久久久亚洲一区 | www.黄色av| 久久女同 | 光棍影院一区二区 | 岛国av大片 | 波多野结衣在线播放视频 | 黄色大片黄色大片 | 色乱码一区二区三区网站 | 快播视频在线观看 | 欧美久草 | 一区视频免费观看 | 影音先锋在线观看视频 | www.亚洲欧美 | 韩国黄色片网站 | 西西人体www大胆高清 | 激情图片在线观看 | 国产精品久久久久久 | 九草视频在线 | 婷婷六月激情 | 少妇在线视频 | 国产第4页| 日本中文字幕网 | 人人射人人插 | 视频在线91 | 在线免费观看中文字幕 | 美女网站免费视频 | 都市激情亚洲综合 | 亚洲成人网在线 | 麻豆91在线播放 | 国产精品色在线 | 久久国产福利 | 六月色婷| 丰满熟女一区二区三区 | 午夜影视大全 | 成人免费看片 | 91网国产| 国产又黄又猛视频 | 亚洲av色香蕉一区二区三区 | 精品国产va久久久久久久 | 丰满秘书被猛烈进入高清播放在 | 99视频热 | 国产色无码精品视频国产 | 一级片特黄 | 精品久久久久久无码人妻 | 波多野结衣在线 | 99综合久久 | 日韩中文字幕在线看 | 中国一级特黄真人毛片免费观看 | 樱花草涩涩www在线播放 | 人妻激情偷乱频一区二区三区 | 午夜精品三级久久久有码 | 136福利视频导航 | 久久加久久 | 狂野欧美 | 一区二区三区福利视频 | a天堂视频在线观看 | 人人免费操 | 国产精品黄色av | 日本一区二区视频 | 97福利网| 日本久久久久 | 五月婷久久 | 超碰成人97 | 四虎国产视频 | 狠色综合 | 黄色片子免费 | 欧美高h视频 | 日韩精品在线电影 | 另类av小说 | 久久99综合 | 中文字幕在线看高清电影 | 精品啪啪| 亚洲熟妇无码av | 浮生影视在线观看免费 | 欧美变态口味重另类在线视频 | 777精品| 91精品国产乱码久久久久久久久 | 欧美视频福利 | 欧美怡春院 | 国产成人精品无码片区在线 | 在线免费看mv的网站入口 | 牛牛在线免费视频 | 极品美女扒开粉嫩小泬 | 国产黄色免费大片 | 成人国产一区二区三区 | 五月中文字幕 | 一级bbbbbbbbb毛片 | 亚洲精品四区 | 午夜精品久久久久久久第一页按摩 | 精品视频成人 | 成人av教育 | 九九99久久 |