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] ...
随机推荐
- SpringMVC 返回json
1.导入jackson的jar包 2.在方法体上加上@ResponseBody /** * 得到ProType的typeId,typeName列表 * 返回json * */ @RequestMapp ...
- Hotaru's problem
Hotaru's problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 大型软件系统客户端数据同步的问题解决
作为一个完整的整体信息化解决方案需要有足够强大的各种功能,这些功能相对独立,又互相依存.当有需要这样的功能时可以随时拿出来用,适当修改一下就可以满足要求.只有这样才能快速开发各种信息化系统,才能满足各 ...
- 遭遇input与button按钮背景图失效不显示的解决办法
笔者从事网页前端代码页面工程师已有多年,作为一个网页重构人员常常会遇到一些莫名其妙的DIV+CSS(正确的说法是XHTML+CSS)在 IE.FireFox火狐. 谷歌浏览器CHROME.苹果浏览器S ...
- [LeetCode] Wiggle Sort
Problem Description: Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[ ...
- 【Jquery】$.Deferred 对象
源:http://www.ruanyifeng.com/ deferred三个状态 “已完成”“未完成”“已失败” (1) $.Deferred() 生成一个deferred对象. ...
- ECharts学习(1)--简单图表的绘制
1.获取ECharts 官网 下载:http://echarts.baidu.com/download.html 2.在html页面中引入ECharts文件 <!DOCTYPE html> ...
- 模仿iframe框架,由分隔栏动态改变左右两侧div大小———基于jQuery
<!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...
- CSS div水平垂直居中和div置于底部
一.水平居中 .hor_center { margin: 0 auto; } 二.水平垂直居中 .content { width: 360px; height: 240px; } .ver_hor_c ...
- perl 模块安装
You can check if you have them installed in your machine with: > perl -e 1 -M<module> It wi ...