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
  • 相关阅读:
    Java暑期学习第三十一天日报
    使用dataadapter和dataset更新数据库
    一些很酷的.Net技
    一个阴历阳历互相转化的类(c#农历)
    详细讲解简洁、明晰!数据库设计三大范式应用实例
    WinForm下ListBox控件“设置DataSource属性后无法修改项集合”的问题解决方案
    CONVERT函数方法大全(经验总结)
    使用C#将字符串转换成十六进制以及其逆转换
    List myList = new List()有关的方法及属性
    C#实现P2P之UDP穿透NAT及其原理讲解11
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3967952.html
Copyright © 2011-2022 走看看