bzoj1108: [POI2007]天然气管道Gaz

题面在这里

题意:

平面上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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值