题意:
平面上2*n的点前n个和后n个两两配对,需要的管道长度是两个点的曼哈顿距离,问最少需要的管道长度。
做法:
sb题啊。
发现怎么配都一样= =(自己画几个图就知道了)
于是直接算就好了。
代码:
/*************************************************************
Problem: bzoj 1108 [POI2007]天然气管道Gaz
User: fengyuan
Language: C++
Result: Accepted
Time: 336 ms
Memory: 1292 kb
Submit_Time: 2018-01-05 13:53:39
*************************************************************/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cctype>
using namespace std;
typedef long long LL;
inline LL read()
{
char ch = getchar(); LL x = 0; int op = 1;
for (; !isdigit(ch); ch = getchar()) if (ch == '-') op = -1;
for (; isdigit(ch); ch = getchar()) x = x*10+ch-'0';
return op*x;
}
inline void write(LL a)
{
if (a < 0) putchar('-'), a = -a;
if (a >= 10) write(a/10); putchar('0'+a%10);
}
int main()
{
int n = read(); LL ans = 0;
for(int i = 1; i <= n; i ++) ans -= read(), ans += read();
for(int i = 1; i <= n; i ++) ans += read(), ans -= read();
write(ans), putchar('\n');
return 0;
}