BZOJ2007——[Noi2010]海拔
1、题意:一个裸的最小割
2、分析:直接转成对偶图最短路就好了,水爆了!(雾)
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 2000010
#define inf 1014748364
inline int read(){
char ch = getchar(); int x = 0, f = 1;
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while('0' <= ch && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
namespace dijkstra{
struct Edge{
int u, v, w, next;
} G[M];
int head[M], tot;
struct Node{
int d, u;
inline bool operator < (const Node& rhs) const{
return d > rhs.d;
}
};
priority_queue<Node> Q;
int d[M];
bool done[M];
inline void init(){
memset(head, -1, sizeof(head));
tot = 0;
}
inline void add(int u, int v, int w){
// printf("%d %d %d\n", u, v, w);
G[++ tot] = (Edge){u, v, w, head[u]};
head[u] = tot;
}
inline int get_dis(int s, int t, int n){
memset(done, 0, sizeof(done));
for(int i = 0; i <= n; i ++) d[i] = inf;
d[s] = 0;
Q.push((Node){0, s});
while(!Q.empty()){
Node u = Q.top(); Q.pop();
int x = u.u;
if(done[x]) continue;
done[x] = 1;
for(int i = head[x]; i != -1; i = G[i].next){
Edge& e = G[i];
if(d[e.v] > d[x] + e.w){
d[e.v] = d[x] + e.w;
Q.push((Node){d[e.v], e.v});
}
}
}
return d[t];
}
}
using namespace dijkstra;
int n;
inline int num(int i, int j){
if(j < 1 || i > n) return 0;
if(i < 1 || j > n) return n * n + 1;
return (i - 1) * n + j;
}
int main(){
n = read();
init();
for(int i = 0; i <= n; i ++){
for(int j = 1; j <= n; j ++){
int x = read();
add(num(i + 1, j), num(i, j), x);
}
}
for(int i = 1; i <= n; i ++){
for(int j = 0; j <= n; j ++){
int x = read();
add(num(i, j), num(i, j + 1), x);
}
}
for(int i = 0; i <= n; i ++){
for(int j = 1; j <= n; j ++){
int x = read();
add(num(i, j), num(i + 1, j), x);
}
}
for(int i = 1; i <= n; i ++){
for(int j = 0; j <= n; j ++){
int x = read();
add(num(i, j + 1), num(i, j), x);
}
}
printf("%d\n", get_dis(0, n * n + 1, n * n + 1));
return 0;
}
BZOJ2007——[Noi2010]海拔的更多相关文章
- Bzoj2007 [Noi2010]海拔(平面图最短路)
2007: [Noi2010]海拔 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2742 Solved: 1318[Submit][Status] ...
- [BZOJ2007][NOI2010]海拔(对偶图最短路)
首先确定所有点的海拔非0即1,问题转化成裸的平面图最小割问题,进而转化成对偶图最短路(同BZOJ1002). 这题的边是有向的,所以所有边顺时针旋转90度即可. 如下图(S和T的位置是反的). #in ...
- Bzoj2007 [Noi2010]海拔
Time Limit: 20 Sec Memory Limit: 552 MB Submit: 2380 Solved: 1130 Description YT市是一个规划良好的城市,城市被东西向 ...
- bzoj2007 NOI2010 海拔(对偶图)
80分(最小割)思路 先考虑如果没有题目中东南角为\(1\)那个限制的话会怎样. 那么只要让每个点的海拔都是\(0\)就行了.这样不论怎样走,最后的答案都是0. 然后再考虑那个东南角为\(1\)的限制 ...
- BZOJ2007 [Noi2010]海拔 【平面图最小割转对偶图最短路】
题目链接 BZOJ2007 题解 这是裸题啊,,要是考试真的遇到就好了 明显是最小割,而且是有来回两个方向 那么原图所有向右的边转为对偶图向下的边 向左的边转为向上 向下转为向左 向上转为向右 然后跑 ...
- bzoj千题计划129:bzoj2007: [Noi2010]海拔
http://www.lydsy.com/JudgeOnline/problem.php?id=2007 1.所有点的高度一定在0~1之间, 如果有一个点的高度超过了1,那么必定会有人先上坡,再下坡, ...
- BZOJ2007 NOI2010 海拔 平面图转对偶图 最小割
题面太长啦,请诸位自行品尝—>海拔 分析: 这是我见过算法比较明显的最小割题目了,很明显对于某一条简单路径,海拔只会有一次变换. 而且我们要最终使变换海拔的边权值和最小. 我们发现变换海拔相当于 ...
- 【BZOJ2007】[Noi2010]海拔 对偶图最短路
[BZOJ2007][Noi2010]海拔 Description YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作 一个正方形,每一个区域也可看 ...
- BZOJ 2007: [Noi2010]海拔
2007: [Noi2010]海拔 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2410 Solved: 1142[Submit][Status] ...
随机推荐
- phabricator在mac上的搭建
环境:OS X Yosemite 10.10.5 前提:phabricator主要是由php写的,而且是以website方式运行的,所以mac上要先安装好 php + nginx(或apache) + ...
- 使用jQuery加载script脚本
原文链接: Loading Scripts with jQuery JavaScript loaders加载器简单强大而又非常有用.我在博客上介绍过其中一些,例如 curljs 和 LABjs ,也 ...
- Caliburn.Micro学习笔记(二)----Actions
Caliburn.Micro学习笔记目录 上一篇已经简单说了一下引导类和简单的控件绑定 我的上一个例子里的button自动匹配到ViewModel事件你一定感觉很好玩吧 今天说一下它的Actions, ...
- C语言初级进阶2
运算符 逻辑运算符: && || ! 位运算符:& | ~ ^ 三目运算符: ? : 结构体元素访问: . -> 命令行参数argc与argv C语言中判断式 各种数据类 ...
- Pycharm如何添加第三方库和插件
首先打开Pycharm,点击左上角 >>File >>Setting . 打开之后点击 >>PRoject :untitled >>Projec ...
- raw_input和input的区别
raw_input的返回类型是String类型 input的返回类型是int类型 >>> rawinput = raw_input("raw_input:") r ...
- python面向对象进阶(八)
上一篇<Python 面向对象初级(七)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...
- JS中的decodeURIComponent和encodeURIComponent
两个函数可以对特定函数生成的密码字符串进行解密操作,就可以生成为未解密的字符串 使用方法: //加密 encodeURIComponent("http://www.cnblogs.com/7 ...
- request 获取服务根目录地址
这是常用的request获取服务地址的常用方式. 源请求服务地址:http://localhost/api-server/1/forum/thread/hot_topic?sex=1 String p ...
- ngBind ngBindTemplate ngBindHtml
ng-bind: 只能绑定一个变量 在AngularJS中显示模型中的数据有两种方式: 一种是使用花括号插值的方式: <p>{{titleStr}}</p> 另一种是使用基于属 ...