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 ...
随机推荐
- 使用vue-cli+webpack搭建vue开发环境
在这里我真的很开心,好久没有用过博客,今天突然看到了我的博客有不少人看过,虽然没有留下脚印,但是还是激起了我重新拿起博客的信心,感谢大家. 在这里我们需要首先下载node,因为我们要用到npm包下载, ...
- SpringMVC、Spring、MyBatis整合(IDEA版)
1 环境准备 1.1 软件架构 JDK 1.8 Spring 4.x Mybatis 3.x Maven 3.x MySQL 5.7 1.2 创建数据库 创建数据库,数据库名ssm-demo,字符集u ...
- 寻找写代码感觉(八)之SpringBoot过滤器的使用
一.什么是过滤器? 过滤器是对数据进行过滤,预处理过程,当我们访问网站时,有时候会发布一些敏感信息,发完以后有的会用*替代,还有就是登陆权限控制等,一个资源,没有经过授权,肯定是不能让用户随便访问的, ...
- RogrePirates Scrum Meeting 博客汇总
RogrePirates 博客目录 一.Scrum Meeting 1.Alpha阶段 第一次会议 第二次会议 第三次会议 第四次会议 第五次会议 第六次会议 第七次会议 第八次会议 第九次会议 第十 ...
- [no code][scrum meeting] Alpha 7
项目 内容 会议时间 2020-04-13 会议主题 OCR技术细节分析 会议时长 30min 参会人员 PM+OCR组成员 $( "#cnblogs_post_body" ).c ...
- Vagrant 搭建开发环境实践
介绍 Development Environments Made Easy -官网标题 vagrant是一个命令行的虚拟机管理程序.用于简化搭建开发环境. vagrant使用ruby语言基于Chef ...
- 替换空格 牛客网 剑指Offer
替换空格 牛客网 剑指Offer 题目描述 请实现一个函数,将一个字符串中的每个空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20A ...
- 绑定socket描述符到一个网络设备
网络编程中有时明明用eth0的地址来bind一个udp套接口, 可是发出去的包却是从eht1走的, 在网上找到这么一段话解释该问题: 在多 IP/网卡主机上,UDP ...
- hdu 5179 beautiful number(构造,,,,)
题意: 一个如果称作是漂亮数,当且仅当满足: 每一位上的数字是[1,9],从高到时低数字大小降序,且有di%dj=0(i<j) 例:931 给一个区间[L,R],问这个区间里有多少个漂亮数. 1 ...
- java实现rsa加密算法【5min快速应用教程】
该篇文章的主要目的是让读者能够迅速应用到项目中,想要了解详细的rsa加密算法的,可以百度找到更多原理.深度分析的文章. RSA算法是一种非对称密码算法,所谓非对称,就是指该算法需要一对密钥,使用其中一 ...