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 ...
随机推荐
- xpath helper插件安装提示程序包无效
参考链接:https://www.jianshu.com/p/b7d782ef81e0 刚学到爬虫,需要在Chrome浏览器安装xpath helper插件结果一直提示"程序包无效" ...
- 初始CSS01
CSS基础知识 CSS介绍 CSS全称为层叠样式表,与HTML相辅相成,实现网页的排版布局与样式美化. 使用方式 根据样式表在页面中呈现的方式不同,可以通过以下三种方式在页面中使用格式 内联样式 改样 ...
- python查询对像所有方法
鉴于学习时好多参数对像都不知道是什么玩意有什么方法,搜了半天一个 """arg为一个对像,下面是打印所有对像方法"""for i, func ...
- [对对子队]事后总结Beta
设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 要做一个游戏,定义的很清楚,实现出来的效果贴近定义,对用户和场景有清晰描述 我们达到目标了么(原计划的功 ...
- Noip模拟50 2021.9.10
已经好长时间没有考试不挂分的良好体验了... T1 第零题 开场数据结构,真爽 对于这道题首先要理解对于一条链从上向下和从下向上走复活次数相等 (这可能需要晚上躺在被窝里面脑摸几种情况的样例) 然后就 ...
- TT模板的作用及使用
一.假如你在ef中添加一个实体,没有模板,你需要在DAL层中新建一个"莫某Dal"和"I某某Dal"以及在公共的DbSession中加你的这个dal,然后需要在 ...
- EasyX安装教程
Easyx是什么 就是一款可以在Windows里让你的C++程序里显示图片等的工具. 注意:EasyX不支持Linux.MacOS.不过还有Qt等可以选择. 安装VC/VS Easyx只支持Visua ...
- 助你上手Vue3全家桶之Vue3教程
目录 前言 1,setup 1.1,返回值 1.2,注意点 1.3,语法 1.4,setup的参数 2,ref 创建响应式数据 3,reactive 创建响应式数据 4,computed 计算属性 5 ...
- [个人开源]vue-code-view:一个在线编辑、实时预览的代码交互组件
组件简介 vue-code-view是一个基于 vue 2.x.轻量级的代码交互组件,在网页中实时编辑运行代码.预览效果的代码交互组件. 使用此组件, 不论 vue 页面还是 Markdown 文档中 ...
- dhcpd 启动失败No subnet declaration for wlan0
今天在调试机器的WIFI热点,好不容易把dhcp编译打包进去,服务启动出现报错No subnet declaration for wlan0,详细信息如下: Internet Systems Cons ...