CF1445E four points
我们不妨枚举四个点的移动方向。
那我们可以直接算出在该情况的最优的答案。
#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的更多相关文章
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [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. ...
- 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 ...
- K closest points
Find the K closest points to a target point in a 2D plane. class Point { public int x; public int y; ...
- 【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 ...
- 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. ...
- [LeetCode OJ] Max Points on a Line
Max Points on a Line Submission Details 27 / 27 test cases passed. Status: Accepted Runtime: 472 ms ...
- [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 ...
- [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 ...
随机推荐
- Oracle-绑定执行计划
一.绑定执行计划 Oracle存在某个SQL多个执行计划的情况,那么如何快速将Oracle 好的执行计划,绑定到不好的SQL上呢? 由于版本的演进,绑定执行计划在10g 一般使用sql profile ...
- OSI模型与TCP/IP模型
OSI模型与TCP/IP模型 OSI参考模型: ---开放式系统互联参考模型 OSI/RM ISO ---国际标准化组织 --1979 应用层 ---- 通过应用进程间的交互来完成特定网络应用 表 ...
- pycharm安装第三方库
https://jingyan.baidu.com/article/4853e1e54b845e1909f7268f.html
- 【UE4 设计模式】观察者模式 Observer Pattern
概述 描述 定义对象间的一种一对多依赖关系,使得每当一个对象状态发生改变时,其相关依赖对象皆得到通知并被自动更新.观察者模式又叫做 发布-订阅(Publish/Subscribe)模式 模型-视图(M ...
- sqlmap--tamper使用技巧
apostrophemask.py 适用数据库:ALL 作用:将引号替换为utf-8,用于过滤单引号 使用脚本前: tamper("1 AND '1'='1") 使用脚本后: 1A ...
- 【二食堂】Alpha - Scrum Meeting 6
Scrum Meeting 6 例会时间:4.16 11:40 - 12:10 进度情况 组员 昨日进度 今日任务 李健 1. 文本区域进度40%,UI需要进行调整issue 1. 继续文本区域的开发 ...
- 2021.8.13考试总结[NOIP模拟38]
T1 a 入阵曲.枚举矩形上下界,之后从左到右扫一遍.用树状数组维护前缀和加特判可以$A$,更保险要脸的做法是双指针扫,因为前缀和单调不减. $code:$ 1 #include<bits/st ...
- IE浏览器——网络集合代理无法启动
用管理员身份运行cmd然后输入 sc config diagnosticshub.standardcollector.service start=demand
- NavigationView使用简介
Android支持直接创建带有NavigationView的Activity,这里主要介绍NavigationView的逻辑. NavigationView通常是跟DrawerLayout一起使用.D ...
- mac bigsur 安装mysql步骤
我首先下载的是mysql8.x,安装完后,在偏好设置里面,双击mysql图标,弹窗:未能载入偏好设置面板MySQL,重启无果,查攻略说是要安装5.7.x,在mysql官网上,下载5.7.29 强烈建议 ...