HDU-3870-Catch the Theves
来源:互联网 发布:知牛财经 编辑:程序博客网 时间:2024/06/06 03:18
ACM模版
描述
题解
用最小割做是要死人的,看了周冬前辈中学时的论文,搞清楚了这种题要转化为最短路搞,不过建起图来是一个恶心人的事情~~~
具体论文参见:浅析最大最小定理在信息学竞赛中的应用
代码
#include <iostream>#include <cstring>#include <vector>#include <queue>using namespace std;const int MAXN = 170000;const int INF = 0x3f3f3f3f;struct point{ int v, w;} Point;vector<point> Edge[MAXN];int n,S,T,q[MAXN];int dist[MAXN];bool inq[MAXN];int SPFA(){ int head = 0, tail = 0; memset(inq, false, sizeof(inq)); for (int i = 0; i <= (n - 1) * (n - 1) + 1; i++) { dist[i] = INF; } q[tail++] = S; dist[S] = 0; inq[S] = true; while (head != tail) { int k = q[head]; head = (head + 1) % MAXN; inq[k] = false; for (int i = 0; i < Edge[k].size(); i++) { Point = Edge[k][i]; if (dist[Point.v] > dist[k] + Point.w) { dist[Point.v] = dist[k] + Point.w; if (!inq[Point.v]) { inq[Point.v] = true; q[tail] = Point.v; tail = (tail + 1) % MAXN; } } } } return dist[T];}int main(){ int t; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 0; i < (n - 1) * (n - 1) + 2; i++) { Edge[i].clear(); } S = (n - 1) * (n - 1); T = (n - 1) * (n - 1) + 1; int w; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &w); Point.w = w; if (i == 0 && j != n - 1) { Point.v = j; Edge[S].push_back(Point); } else if (j == n - 1 && i != n - 1) { Point.v = i * (n - 1) + j - 1; Edge[S].push_back(Point); } if (j == 0 && i != n - 1) { Point.v = T; Edge[i * (n - 1)].push_back(Point); } else if (i == n - 1 && j != n - 1) { Point.v = T; Edge[(n - 2) * (n - 1) + j].push_back(Point); } if (i != n - 1 && j != n - 1) { if (i) { Point.v = (i - 1) * (n - 1) + j; Edge[i * (n - 1) + j].push_back(Point); Point.v = i * (n - 1) + j; Edge[(i - 1) * (n - 1) + j].push_back(Point); } if (j) { Point.v = i * (n - 1) + j - 1; Edge[i * (n - 1) + j].push_back(Point); Point.v = i * (n - 1) + j; Edge[i * (n - 1) + j - 1].push_back(Point); } } } } printf("%d\n", SPFA()); } return 0;}
0 0
- HDU 3870 Catch the Theves
- HDU 3870Catch the Theves
- HDU-3870-Catch the Theves
- hdu 3870 Catch the Theves(平面最小割)
- 平面图s-t最小割 HDU 3870 Catch the Theves
- hdu 3870 Catch the Theves 平面图转对偶图
- HDU 3870 Catch the Theves 最短路求最小割
- 【最短路】 HDOJ 3870 Catch the Theves
- HDU 3870 Catch the Theves 2011 Multi-University Training Contest 4 - Host by SDU
- 【HDU】3870 Catch the Theves 对偶图全局最小割 最短路
- HDU - 3870 Catch the Theves(最小割+对偶图==最短路)
- hdu 3870 Catch the Theves(对偶图,最短路,最小割)
- HDU 3870 Catch the Theves(对偶图的最小割转最短路)
- HDU3870 Catch the Theves 题解(平面图最小割转最短路)
- hdu catch the thief
- 重做catch the cow
- Catch The Cow
- catch the cow (P3278)
- springboot学习(一)认识springboot及创建第一个springboot项目
- 关于日期时间开发
- Spring AOP三种配置详细介绍
- ADO
- 移动手机开发meta注意问题
- HDU-3870-Catch the Theves
- PHP开发小技巧⑧—CURL请求
- Git stash
- AppStore商店App的相关信息的获取
- C++小知识
- spring @Transactional
- 百度地图Javascript Api定位
- oracle 切割字符按串完成列转行
- 什么是I帧以及如何判断I帧