首页 技术 正文
技术 2022年11月8日
0 收藏 524 点赞 1,262 浏览 1438 个字

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

BZOJ1108: [POI2007]天然气管道Gaz

Source

题解:

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

发现漏看了两句话:

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

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

1s变水题。。。

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

代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 50000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n;
ll sx[],sy[];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for0(i,)
for1(j,n)
sx[i]+=read(),sy[i]+=read();
printf("%lld\n",abs(sx[]-sx[])+abs(sy[]-sy[]));
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289