[NOIP2017模拟]匹配

2017.10.16 T1 1983

样例数据
输入

3
3 5
1 2
4 3
6 3
5 2
2 1

输出

9

分析:由于白点永远在黑点右下方,所以曼哈顿距离就可以去掉绝对值了,最后所有的距离之和就是 sum(x)sum(x)+sum(y)sum(y) 。脑经急转弯……我还想了好久怎么求“最短”距离……

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#include<queue>
#include<set>
using namespace std;

int getint()
{
    int sum=0,f=1;
    char ch;
    for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
    if(ch=='-')
    {
        f=-1;
        ch=getchar();
    }
    for(;isdigit(ch);ch=getchar())
        sum=(sum<<3)+(sum<<1)+ch-48;
    return sum*f;
}

int n;
long long x,y,sumx,sumy;

int main()
{
    freopen("match.in","r",stdin);
    freopen("match.out","w",stdout);

    n=getint();
    for(int i=1;i<=n;++i)
    {
        x=getint(),y=getint();
        sumx-=x;
        sumy+=y;
    }

    for(int i=1;i<=n;++i)
    {
        x=getint(),y=getint();
        sumx+=x;
        sumy-=y;
    }

    cout<<sumx+sumy;
    return 0;
}

本题结。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值