我们不妨枚举四个点的移动方向。

那我们可以直接算出在该情况的最优的答案。

#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
int a[4], b[4], c[4];
int main() {
int _;
scanf("%d", &_);
while (_--) {
for (int i = 0; i < 4; i++) {
scanf("%d%d", &a[i], &b[i]);
c[i] = i;
}
LL ans = 1e18;
while (1) {
LL x0 = a[c[0]], y0 = b[c[0]];
LL x1 = a[c[1]], y1 = b[c[1]];
LL x2 = a[c[2]], y2 = b[c[2]];
LL x3 = a[c[3]], y3 = b[c[3]];
LL now = abs(x0 - x2) + abs(x1 - x3) + abs(y0 - y1) + abs(y2 - y3);
LL r1 = max(x1, x3) - min(x0, x2), l1 = min(x1, x3) - max(x0, x2);
LL r2 = max(y0, y1) - min(y2, y3), l2 = min(y0, y1) - max(y2, y3);
now += 2 * max(0LL, max(l1, l2) - min(r1, r2));
if (r1 >= 0 && r2 >= 0)
ans = min(ans, now);
if (next_permutation(c, c + 4) == 0) break;
}
cout << ans << endl;
}
return 0;
}

CF1445E four points的更多相关文章

  1. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  2. [LeetCode] Max Points on a Line 共线点个数

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  3. LeetCode:Max Points on a Line

    题目链接 Given n points on a 2D plane, find the maximum number of points that lie on the same straight l ...

  4. K closest points

    Find the K closest points to a target point in a 2D plane. class Point { public int x; public int y; ...

  5. 【leetcode】Max Points on a Line

    Max Points on a Line 题目描述: Given n points on a 2D plane, find the maximum number of points that lie ...

  6. Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  7. [LeetCode OJ] Max Points on a Line

    Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...

  8. [UCSD白板题] Points and Segments

    Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...

  9. [UCSD白板题] Covering Segments by Points

    Problem Introduction You are given a set of segments on a line and your goal is to mark as few point ...

随机推荐

  1. ZooKeeper分布式配置——看这篇就够了

    ZooKeeper 的由来 PS:这一节不重要, 不感兴趣的小伙伴可以跳过 ZooKeeper 最早起源于雅虎研究院的一个研究小组,在当时,研究人员发现,在雅虎内部有很多的大型系统基本上都需要依赖一个 ...

  2. 什么是产品待办列表?(What is Product Backlog)

    正如scrum指南中所描述的,产品待办事项列表是一个紧急而有序的列表,其中列出了改进产品所需的内容.它是scrum团队承担的工作的唯一来源. 在sprint计划 (Sprint Planning)活动 ...

  3. UltraSoft - Beta - 设计与计划

    在DDL Killer的Alpha发布版本一周后,我们积累了一定的用户数量和用户反馈,同时也着手准备Beta阶段的继续开发,在正式开始迭代前,先对我们的Beta阶段的需求做一个统计和预估,一是保证工作 ...

  4. 第二次Alpha Scrum Meeting

    本次会议为Alpha阶段第二次Scrum Meeting会议 会议概要 会议时间:2021年4月24日 会议地点:线上会议 会议时长:30min 会议内容简介:本次会议主要由每个人展示自己目前完成的工 ...

  5. 【二食堂】Beta - Scrum Meeting 8

    Scrum Meeting 8 例会时间:5.22 20:00~20:10 进度情况 组员 当前进度 今日任务 李健 1. UI优化已经完成,顺带修复了一点小bug.issue 1. 文本导入.保存部 ...

  6. [对对子队]会议记录4.21(Scrum Meeting12)

    今天已完成的工作 吴昭邦 ​ 工作内容:基本实现改变顺序合成 ​ 相关issue:实现流水线合成系统的逻辑 ​ 相关签入:4.21签入1 梁河览 ​ 工作内容:修改设置界面bug ​ 相关签入:4.2 ...

  7. 设置nginx进程可打开最大的文件数

    涉及到的nginx配置参数: worker_processes: 表示操作系统启动多少个工作进程在运行,一般这个参数设置成CPU核数的倍数 worker_connections:表示nginx的工作进 ...

  8. GEOS使用记录

    由于需要计算GIS障碍物的缓冲区,所以研究了 一下GEOS库的使用,将使用的一些细节内容记录一下: 1.vs2010IDE无法编译较高版本的GEOS库,较高版本的库使用了更加高级的C++语法,如果想使 ...

  9. Linux多线程编程实例解析

    Linux系统下的多线程遵循POSIX线程接口,称为 pthread.编写Linux下的多线程程序,需要使用头文件pthread.h,连接时需要使用库libpthread.a.顺便说一下,Linux ...

  10. 【TLS】-TLS/SSL笔记

    目录 前言 概念 对称加密 非对称加密 公钥 单向加密 数字签名 基础 作用 SSL/TLS 模型 运作 问题&解答 基本过程 握手阶段 客户端发出请求(ClientHello) 服务器回应( ...