2007: [Noi2010]海拔

https://www.lydsy.com/JudgeOnline/problem.php?id=2007

分析:

  平面图最小割。

  S在左下,T在右上,从S到T的一个路径使得路径右下方全是1,左上方全是0。

  一个问题:每个点的高度只能是0/1,所以有些边是一定不能选的,就让它连向S,不影响。

代码:

 /*
平面图最小割
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cctype>
#include<queue>
using namespace std;
typedef long long LL; inline int read() {
int x = , f = ; char ch = getchar(); for (; !isdigit(ch); ch=getchar()) if (ch=='-') f = -;
for (; isdigit(ch); ch=getchar()) x = x * + ch - ''; return x * f;
} const int N = ;
struct Edge{
int to, w, nxt;
Edge() {}
Edge(int a,int b,int c) {to = a, w = b, nxt = c;}
}e[];
struct Node{
int u;
LL dis;
Node() {}
Node(int a,LL b) {u = a, dis = b;}
bool operator < (const Node &A) const {
return dis > A.dis;
}
};
int head[N];
LL dis[N];
int Enum, n;
bool vis[N];
priority_queue<Node> q; void add_edge(int u,int v,int w) {
e[++Enum] = Edge(v, w, head[u]); head[u] = Enum;
// cout << u << " " << v << " " << w << '\n';
} int get(int i,int j) {
return (i - ) * n + j;
} int Dijkstra(int S,int T) {
for (int i=; i<=T; ++i) dis[i] = 1e18, vis[i] = false;
dis[S] = ;
q.push(Node(S,));
Node now, nxt;
while (!q.empty()) {
now = q.top(); q.pop();
int u = now.u;
if (vis[u]) continue;
vis[u] = true;
for (int i=head[u]; i; i=e[i].nxt) {
int v = e[i].to;
if (dis[v] > dis[u] + e[i].w) {
dis[v] = dis[u] + e[i].w;
q.push(Node(v,dis[v]));
}
}
}
return dis[T];
} int main() {
n = read();
int S = , T = n * n + ; for (int i=; i<=n+; ++i) { // 左 -> 右, 下 -> 上
for (int j=; j<=n; ++j) {
int w = read();
if (i == ) add_edge(get(i, j), T, w);
else if (i == n + ) add_edge(S, get(i - , j), w);
else add_edge(get(i, j), get(i - , j), w);
}
} for (int i=; i<=n; ++i) { // 上 -> 下 , 左 -> 右
for (int j=; j<=n+; ++j) {
int w = read();
if (j == ) add_edge(S, get(i, j), w);
else if (j == n + ) add_edge(get(i, j - ), T, w);
else add_edge(get(i, j - ), get(i, j), w);
}
} for (int i=; i<=n+; ++i) { // 右 -> 左 , 上 -> 下
for (int j=; j<=n; ++j) {
int w = read();
if (i == ) add_edge(T, get(i, j), w);
else if (i == n + ) add_edge(get(i - , j), S, w);
else add_edge(get(i - , j), get(i, j), w);
}
} for (int i=; i<=n; ++i) { // 下 -> 上 , 右 - > 左
for (int j=; j<=n+; ++j) {
int w = read();
if (j == ) add_edge(get(i, j), S, w);
else if (j == n + ) add_edge(T, get(i, j - ), w);
else add_edge(get(i, j), get(i, j - ), w);
}
}
printf("%d",Dijkstra(S, T));
return ;
}

2007: [Noi2010]海拔的更多相关文章

  1. BZOJ 2007: [Noi2010]海拔

    2007: [Noi2010]海拔 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 2410  Solved: 1142[Submit][Status] ...

  2. 【BZOJ 2007】 2007: [Noi2010]海拔 (平面图转对偶图+spfa)

    2007: [Noi2010]海拔 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 2504  Solved: 1195 Description YT市 ...

  3. 2007: [Noi2010]海拔 - BZOJ

    Description YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作一个正方形,每一个区域也可看作一个正方形.从而,YT城市中包括(n+1)× ...

  4. [BZOJ 2007] [Noi2010] 海拔 【平面图最小割(对偶图最短路)】

    题目链接:BZOJ - 2007 题目分析 首先,左上角的高度是 0 ,右下角的高度是 1.那么所有点的高度一定要在 0 与 1 之间.然而选取 [0, 1] 的任何一个实数,都可以用整数 0 或 1 ...

  5. BZOJ.2007.[NOI2010]海拔(最小割 对偶图最短路)

    题目链接 想一下能猜出,最优解中海拔只有0和1,且海拔相同的点都在且只在1个连通块中. 这就是个平面图最小割.也可以转必须转对偶图最短路,不然只能T到90分了..边的方向看着定就行. 不能忽略回去的边 ...

  6. bzoj 2007 [Noi2010]海拔——最小割转最短路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2007 一个点的高度一定不是0就是1.答案一定形如一个左上角的连通块全是0的点.一个右下角的连 ...

  7. 【BZOJ】2007: [Noi2010]海拔(平面图转对偶图)

    题目 传送门:QWQ 分析 左上角是0,右下角是1.那么大概整张图是由0 1构成的. 那么我们要找到0和1的分界线,值就是最小割. 然后变成求原图最小割. 考虑到此题是平面图,那么就转成对偶图跑最短路 ...

  8. bzoj 2007: [Noi2010]海拔【最小割+dijskstra】

    上来就跑3e5的最大流--脑子抽了 很容易看出,每个地方的海拔都是0或1因为再高了没有意义,又,上去下来再上去没有意义,所以最后一定是从s连着一片0,剩下连着t一片1,然后有贡献的就是01交接的那些边 ...

  9. NOI2010海拔

    2007: [Noi2010]海拔 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 1302  Solved: 612[Submit][Status] ...

随机推荐

  1. OO思想举例,控制翻转,依赖注入

    (转自kumaws,原帖地址:http://www.cnblogs.com/kumaws/archive/2009/04/06/from_interface_to_DependencyInjectio ...

  2. 编程思想的理解(POP,OOP,SOA,AOP) x

    http://blog.chinaunix.net/uid-29417436-id-4060980.html 1)POP--面向过程编程(Process-oriented programming ): ...

  3. 4519: [Cqoi2016]不同的最小割

    4519: [Cqoi2016]不同的最小割 Time Limit: 20 Sec Memory Limit: 512 MB Submit: 489 Solved: 301 [Submit][Stat ...

  4. HDU 1298 T9【字典树增加||查询】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1298 T9 Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  5. [18/11/20]break与continue的区别

    一.普通break 和continue 1.break: break用于强行退出循环,不执行循环中剩余的语句. 2.continue continue 语句用在循环语句体中,用于终止某次循环过程,即跳 ...

  6. jmeter报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"的解决方法

    1.报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supporte ...

  7. 2017.9.12 初入HTML -----学习总结(二)

    接上:..... (4)标记可分为: 4.1单标记:(单标记仅单独使用就可以表达完整的意思) 基本语法:<标记名称/> 例如:<br/>实现换行的功能.<hr/>实 ...

  8. 【洛谷P3959】[NOIP2017] 宝藏

    宝藏 题目链接 首先,打了一个prim,得了45分 #include<iostream> #include<cstring> #include<cstdio> #i ...

  9. 如何用Redlock实现分布式锁

    转载请标明出处: http://blog.csdn.net/forezp/article/details/70305336 本文出自方志朋的博客 之前写过一篇文章<如何在springcloud分 ...

  10. javascript 六种基本数据类型转换

    javascript 六种基本数据类型转换 1.显式转换 通过手动进行类型转换,Javascript提供了以下转型函数: 转换为数值类型:Number(mix).parseInt(string,rad ...