题意:

给N个点求任意两个点的“距离”总和:

A,B的“距离”定义为:min(|ax-bx|,|ay-by|) (n<200000)

好题!

解析:

看着没思路

先是公式化简:让 ax=sx+sy;

ay=sx-sy;

bx=tx+ty;

by=tx-ty;

于是:min(|ax-bx|,|ay-by|)=min(ax-bx,bx-ax,ay-by,by-ay)=min(sx-tx+sy-ty,tx-sx+ty-sy,sx-tx+sy-ty,tx-sx+ty-sy);

=|sx-tx|+|sy-ty|

这里就明显了吧:

sx=(ax+ay)/2 sy=(ax-ay)/2

于是分别按sx,sy排序;

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <vector> #define ll long long
#define N 222222 ll a[N],b[N];
using namespace std; int main()
{
int T;
scanf("%d",&T);
while (T--)
{
int n,c,d;
scanf("%d%d%d",&n,&c,&d);
for (int i=;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
a[i]=(ll) c*x+d*y;
b[i]=(ll) c*x-d*y;
} sort(a+,a+n+);
sort(b+,b+n+); ll ans=;
ll ans1=;
for (int i=;i<=n;i++)
{
ans1+=a[i];
ans+=a[i]*i-ans1;
}
ans1=;
for (int i=;i<=n;i++)
{
ans1+=b[i];
ans+=b[i]*i-ans1;
}
printf("%lld\n",ans>>);
}
return ;
}

codechef Taxi Driver的更多相关文章

  1. Lesson 29 Taxi!

    Text Captain Ben Fawcett has bought an unusual taxi and has begun a new serivice. The 'taxi' is a sm ...

  2. CF 1100E Andrew and Taxi(二分答案)

    E. Andrew and Taxi time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Lyft Level 5 Challenge 2018-Final Round(Open Div.2) B. Taxi drivers and Lyft

    http://codeforces.com/contest/1075/problem/B Palo Alto is an unusual city because it is an endless c ...

  4. ACM: 限时训练题解-Heavy Coins-枚举子集-暴力枚举

    Heavy Coins   Bahosain has a lot of coins in his pocket. These coins are really heavy, so he always ...

  5. C++程序结构---1

    C++ 基础教程Beta 版 原作:Juan Soulié 翻译:Jing Xu (aqua) 英文原版 本教程根据Juan Soulie的英文版C++教程翻译并改编. 本版为最新校对版,尚未定稿.如 ...

  6. BBC票选出的100部最经典美国电影,你看过几部?

    BBC票选出的100部最经典美国电影,你看过几部? 导读:BBC票选出的100部最经典美国电影,你看过几部? 2015-07-27欧美内参欧美内参欧美内参 微信号zoujinoumei 功能介绍< ...

  7. 人一生必看的100部电影(全球最佳电影排名榜TOP250)

    人一生必看的100部电影(全球最佳电影排名榜TOP250) 人的一生能看多少部电影?假设我们每周都看一部,从10岁看到80岁将会看3640部.但是我们也不可能喜欢这全部的电影.大多数的可能,我们会根据 ...

  8. (转) Data structures

      Data structures A data structure is a group of data elements grouped together under one name. Thes ...

  9. As3.0 Interface 与类的使用

    来源:http://blog.sina.com.cn/s/blog_4d65c19e0100bfkb.html 抽象类:又叫抽象基类:可以包含一般类所包含的所有特性,例如,字段,属性,方法,抽象类不能 ...

随机推荐

  1. mac osx上为qt应用生成debug symbol

    mac平台上,希望Qt编译的release程序也能包含debug symbol,这样出问题以后便于查找问题 开始按照http://doc.qt.io/qt-4.8/mac-differences.ht ...

  2. MYSQL 二次筛选,统计,最大值,最小值,分组,靠拢

    HAVING 筛选后再 筛选 SELECT CLASS,SUM(TOTAL_SCORES) FROM student_score GROUP BY CLASS HAVING SUM(TOTAL_SCO ...

  3. vijos 1053 Easy sssp

    描述 输入数据给出一个有N(2 <= N <= 1,000)个节点,M(M <= 100,000)条边的带权有向图. 要求你写一个程序, 判断这个有向图中是否存在负权回路. 如果从一 ...

  4. (转)编码剖析Spring管理Bean的原理

    http://blog.csdn.net/yerenyuan_pku/article/details/52832434 在Spring的第一个案例中,我们已经知道了怎么将bean交给Spring容器进 ...

  5. (转)Spring的bean管理(注解方式)

    http://blog.csdn.net/yerenyuan_pku/article/details/69663779 Spring的bean管理(注解方式) 注解:代码中的特殊标记,注解可以使用在类 ...

  6. elasticsearch时间格式DateFormat的含义

    时间格式 枚举(或者英文)format pattern 含义 custom - 自定义属性 none - 不转化 basic_date yyyyMMdd 基本时间 basic_date_time   ...

  7. js将时间戳装换成日期格式

    13位时间戳改为yyyy-MM-dd HH-mm-ss 格式 目标时间戳:1516324500000 formatDateTime (unix) { // 转换时间戳 var date = new D ...

  8. 加快create-react-app的方法

    npm config get registry 查看npm源,默认源是 https://registry.npmjs.org/ npm config set registry https://regi ...

  9. Python---哈夫曼树---Huffman Tree

    今天要讲的是天才哈夫曼的哈夫曼编码,这是树形数据结构的一个典型应用. !!!敲黑板!!!哈夫曼树的构建以及编码方式将是我们的学习重点. 老方式,代码+解释,手把手教你Python完成哈夫曼编码的全过程 ...

  10. 在ios中使用FMDB

    SQLite (http://www.sqlite.org/docs.html) 是一个轻量级的关系数据库.iOS SDK很早就支持了SQLite,在使用时,只需要加入 libsqlite3.dyli ...