• B1108 [POI2007]天然气管道Gaz 贪心


    啊啊啊,这题有毒。我想了各种花式数据结构,最后告诉我贪心???受不了。。。

    题干:

    Description
    
      Mary试图控制成都的天然气市场。专家已经标示出了最好的天然气井和中转站在成都的地图。现在需要将中转
    站和天然气井连接起来。每个中转站必须被连接到正好一个钻油井,反之亦然。 Mary特别指名,建设的天然气管
    道必须从某个天然气井开始,向南或者向东建设。Mary想知道怎么连接每个天然气井和中转站,使得需要的天然气
    管道的总长度最小。
    Input
      第一行为一个正整数n(2<=n<=50000),表示天然气井的数量(中转站的数量与之相等)。接下来n行,每行两
    个整数xi和yi(0<=xi,yi<=100000),表示天然气井的坐标。向东走则x坐标增加,向北走则y坐标增加。接下来n
    行,每行两个数xj'和yj'0<=xj',yj'<=100000),表示中转站的坐标。
    Output
      第一行包含一个数,表示最短的连接管道长度。
    Sample Input
    3
    3 5
    1 2
    4 3
    6 3
    5 2
    2 1
    Sample Output
    9
    HINT
    Source

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<ctime>
    #include<queue>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    #define duke(i,a,n) for(int i = a;i <= n;i++)
    #define lv(i,a,n) for(int i = a;i >= n;i--)
    #define clean(a) memset(a,0,sizeof(a))
    const int INF = 1 << 30;
    typedef long long ll;
    typedef double db;
    template <class T>
    void read(T &x)
    {
        char c;
        bool op = 0;
        while(c = getchar(), c < '0' || c > '9')
            if(c == '-') op = 1;
        x = c - '0';
        while(c = getchar(), c >= '0' && c <= '9')
            x = x * 10 + c - '0';
        if(op) x = -x;
    }
    template <class T>
    void write(T x)
    {
        if(x < 0) putchar('-'), x = -x;
        if(x >= 10) write(x / 10);
        putchar('0' + x % 10);
    }
    ll tot = 0;
    int main()
    {
        int n;
        read(n);
        duke(i,1,n)
        {
            ll x,y;
            read(x);read(y);
            tot -= x;
            tot += y;
        }
        duke(j,1,n)
        {
            ll x,y;
            read(x);read(y);
            tot += x;
            tot -= y;
        }
        write(tot);
        return 0;
    }
  • 相关阅读:
    同一个硬盘安装win10+ubuntu双系统
    Bundle
    layout_weight属性
    Java反射机制
    Android——Widget实现
    Android——悬浮窗+侧边弹框+淡入淡出+背景shape+SeekBar调节手机亮度
    Android权限总结
    Android——窗口层控制WindowManager.LayoutParams.type
    Android——getSystemService
    Eclipse UML插件——AmaterasUML
  • 原文地址:https://www.cnblogs.com/DukeLv/p/9544913.html
Copyright © 2020-2023  润新知