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]海拔的更多相关文章

  1. Bzoj2007 [Noi2010]海拔(平面图最短路)

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

  2. [BZOJ2007][NOI2010]海拔(对偶图最短路)

    首先确定所有点的海拔非0即1,问题转化成裸的平面图最小割问题,进而转化成对偶图最短路(同BZOJ1002). 这题的边是有向的,所以所有边顺时针旋转90度即可. 如下图(S和T的位置是反的). #in ...

  3. Bzoj2007 [Noi2010]海拔

    Time Limit: 20 Sec  Memory Limit: 552 MB Submit: 2380  Solved: 1130 Description YT市是一个规划良好的城市,城市被东西向 ...

  4. bzoj2007 NOI2010 海拔(对偶图)

    80分(最小割)思路 先考虑如果没有题目中东南角为\(1\)那个限制的话会怎样. 那么只要让每个点的海拔都是\(0\)就行了.这样不论怎样走,最后的答案都是0. 然后再考虑那个东南角为\(1\)的限制 ...

  5. BZOJ2007 [Noi2010]海拔 【平面图最小割转对偶图最短路】

    题目链接 BZOJ2007 题解 这是裸题啊,,要是考试真的遇到就好了 明显是最小割,而且是有来回两个方向 那么原图所有向右的边转为对偶图向下的边 向左的边转为向上 向下转为向左 向上转为向右 然后跑 ...

  6. bzoj千题计划129:bzoj2007: [Noi2010]海拔

    http://www.lydsy.com/JudgeOnline/problem.php?id=2007 1.所有点的高度一定在0~1之间, 如果有一个点的高度超过了1,那么必定会有人先上坡,再下坡, ...

  7. BZOJ2007 NOI2010 海拔 平面图转对偶图 最小割

    题面太长啦,请诸位自行品尝—>海拔 分析: 这是我见过算法比较明显的最小割题目了,很明显对于某一条简单路径,海拔只会有一次变换. 而且我们要最终使变换海拔的边权值和最小. 我们发现变换海拔相当于 ...

  8. 【BZOJ2007】[Noi2010]海拔 对偶图最短路

    [BZOJ2007][Noi2010]海拔 Description YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作 一个正方形,每一个区域也可看 ...

  9. BZOJ 2007: [Noi2010]海拔

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

随机推荐

  1. mybatis缓存

    mybatis缓存http://www.cnblogs.com/QQParadise/articles/5109633.htmlhttp://www.mamicode.com/info-detail- ...

  2. Android 官方推荐 : DialogFragment 创建对话框

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37815413 1. 概述 DialogFragment在android 3.0时 ...

  3. zookeeper安装

    http://blog.itpub.net/27099995/viewspace-1394831/ http://blog.csdn.net/huwei2003/article/details/491 ...

  4. UCenter创始人密码正确但是登录不了

    UCenter创始人密码正确但是登录不了,没有什么提示,就反复输入密码登录 也进不了......... ================================================ ...

  5. 初学C#和MVC的一些心得,弯路,总结,还有教训(2)--关于Entity Framework

    看了一堆视频教程后,感觉基本了解的差不多了,可以动手.....因为最好的学习方法就是实践嘛.... 所以打算从网站做起,在WebForm和MVC之间选了MVC,因为感觉高大上...也比较灵活 于是买了 ...

  6. 深入理解Java:类加载机制及反射

    说明:本文乃学习整理参考而来. 一.Java类加载机制 1.概述 Class文件由类装载器装载后,在JVM中将形成一份描述Class结构的元信息对象,通过该元信息对象可以获知Class的结构信息:如构 ...

  7. 微博公众平台(二)-- Token验证代码

    Token,验证逻辑:1.将Token.timestamp.nonce放入数组 2.将数组从小到大排列 3.将数组按顺序拼装成一个字符串 4.对生成的字符串进行SHA1加密 5.将密文转换为小写 6. ...

  8. 怎样让 Web 项目暴露在外的服务坚不可摧?

    Web 项目一般给特定人群使用,有些是局域网用户量不足1K的内部系统,也有些广域网用户上万的中型项目,当然还有用户上亿的大型项目. 这些大大小小的 Web 项目都会有用户登录的存在,登录后有特定的权限 ...

  9. css实现了hover显示title的效果

    <div data-title="hello, world">hello...</div> <style> div { position: re ...

  10. 扩展htmlhelper.DropDownListFor 支持list数据源和option增加属性

    mvc自带的DropDownListFor数据源必须是IEnumerable<SelectListItem>.并且option不支持增加自定义属性.在使用bootstrap-select组 ...