zoukankan      html  css  js  c++  java
  • BZOJ1108: [POI2007]天然气管道Gaz

    1108: [POI2007]天然气管道Gaz

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 410  Solved: 211
    [Submit][Status]

    Description

    Mary 试图控制成都的天然气市场。专家已经标示出了最好的天然气井和中转站在成都的地图。现在需要将中转站和天然气井连接起来。每个中转站必须被连接到正好一个 钻油井,反之亦然。 Mary特别指名,建设的天然气管道必须从某个天然气井开始,向南或者向东建设。Mary想知道怎么连接每个天然气井和中转站,使得需要的天然气管道的总 长度最小。

    Input

    输入文件的第一行为一个正整数 n(2<=n<=50000),表示天然气井的数量(中转站的数量与之相等)。接下来n行,每行两个整数xi和yi(0& lt;=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

    题解:

    乍一看题目,卧操,这不是KM吗?n=50000?。。。。。。。。然后果断膜拜题解。。。

    发现漏看了两句话:

    1.天然井必须向南或向东建设管道

    2.是曼哈顿距离而不是欧几里得距离

    1s变水题。。。

    不管每个点与谁相连,它的横纵坐标总会被作为减数的一部分,所以把两部分的x,y都加起来减一下取个绝对值即可。

    代码:

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<iostream>
     7 #include<vector>
     8 #include<map>
     9 #include<set>
    10 #include<queue>
    11 #include<string>
    12 #define inf 1000000000
    13 #define maxn 50000
    14 #define maxm 500+100
    15 #define eps 1e-10
    16 #define ll long long
    17 #define pa pair<int,int>
    18 #define for0(i,n) for(int i=0;i<=(n);i++)
    19 #define for1(i,n) for(int i=1;i<=(n);i++)
    20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    21 using namespace std;
    22 inline int read()
    23 {
    24     int x=0,f=1;char ch=getchar();
    25     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    26     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    27     return x*f;
    28 }
    29 int n;
    30 ll sx[2],sy[2];
    31 int main()
    32 {
    33     freopen("input.txt","r",stdin);
    34     freopen("output.txt","w",stdout);
    35     n=read();
    36     for0(i,1)
    37      for1(j,n)
    38       sx[i]+=read(),sy[i]+=read();
    39     printf("%lld
    ",abs(sx[0]-sx[1])+abs(sy[0]-sy[1]));
    40     return 0;
    41 }
    View Code
  • 相关阅读:
    zoj 2316 Matrix Multiplication 解题报告
    BestCoder7 1001 Little Pony and Permutation(hdu 4985) 解题报告
    codeforces 463C. Gargari and Bishops 解题报告
    codeforces 463B Caisa and Pylons 解题报告
    codeforces 463A Caisa and Sugar 解题报告
    CSS3新的字体尺寸单位rem
    CSS中文字体对照表
    引用外部CSS的link和import方式的分析与比较
    CSS样式表引用方式
    10个CSS简写/优化技巧
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3967952.html
Copyright © 2011-2022 走看看