地址 https://leetcode-cn.com/problems/minimum-time-visiting-all-points/submissions/

题目描述
平面上有 n 个点,点的位置用整数坐标表示 points[i] = [xi, yi]。请你计算访问所有这些点需要的最小时间(以秒为单位)。

你可以按照下面的规则在平面上移动:

每一秒沿水平或者竖直方向移动一个单位长度,或者跨过对角线(可以看作在一秒内向水平和竖直方向各移动一个单位长度)。
必须按照数组中出现的顺序来访问这些点。

样例

示例1
输入:points = [[,],[,],[-,]]
输出:
解释:一条最佳的访问路径是: [,] -> [,] -> [,] -> [,] -> [,] -> [,] -> [,] -> [-,]
从 [,] 到 [,] 需要 秒
从 [,] 到 [-,] 需要 秒
一共需要 秒 示例2
输入:points = [[,],[-,]]
输出:
提示: points.length == n
<= n <=
points[i].length ==
- <= points[i][], points[i][] <=

算法1
若两点不在一条直线上 优先走斜线是最优的 同时减少横向和竖向的距离
走斜线意味着横向竖向同时增加相同单位
所以也意味着 走横向和竖向之差中 较小的值(走斜向)
然后再走横向和竖向之差中两个值得差(表示走竖向或者走横向)

C++ 代码

class Solution {
public:
int minTimeToVisitAllPoints(vector<vector<int>>& points) {
int sum = ;
for(int i = ; i < points.size()-;i++){
int xx = abs(points[i][] - points[i+][]);
int yy = abs(points[i][] - points[i+][]);
sum += min(xx,yy);
sum += max(xx,yy) - min(xx,yy);
} return sum;
}
};

LeetCode 5271. 访问所有点的最小时间 Minimum Time Visiting All Points的更多相关文章

  1. leetcode.1266访问所有点的最小时间

    平面上有 n 个点,点的位置用整数坐标表示 points[i] = [xi, yi].请你计算访问所有这些点需要的最小时间(以秒为单位). 你可以按照下面的规则在平面上移动: 每一秒沿水平或者竖直方向 ...

  2. leetcode 1266. Minimum Time Visiting All Points

    On a plane there are n points with integer coordinates points[i] = [xi, yi]. Your task is to find th ...

  3. 【leetcode】1266. Minimum Time Visiting All Points

    题目如下: On a plane there are n points with integer coordinates points[i] = [xi, yi]. Your task is to f ...

  4. hdu 5067 遍历指定点集最小时间

    http://acm.hdu.edu.cn/showproblem.php?pid=5067 贴题解 由于Harry的dig machine是无限大的,而装载石头和卸载石头是不费时间的,所以问题可以转 ...

  5. java8 获取某天最大(23:59:59)和最小时间(00:00:00)

    public class DateUtil { // 获得某天最大时间 2018-03-20 23:59:59 public static Date getEndOfDay(Date date) { ...

  6. LeetCode:访问所有节点的最短路径【847】

    LeetCode:访问所有节点的最短路径[847] 题目描述 给出 graph 为有 N 个节点(编号为 0, 1, 2, ..., N-1)的无向连通图. graph.length = N,且只有节 ...

  7. [LeetCode] Next Closest Time 下一个最近时间点

    Given a time represented in the format "HH:MM", form the next closest time by reusing the ...

  8. MS Chart-按照数据库的最大最小时间设置X轴label.

    核心代码: Chart1.ChartAreas[0].AxisX.Interval = (Front_Max - Front_Min).Days / 2; Chart1.ChartAreas[0].A ...

  9. Python3基础 getatime getctime getmtime 文件的最近访问 + 属性修改 + 内容修改时间

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

随机推荐

  1. Additional information: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding elemen

    wcf service: <system.serviceModel> <bindings> <basicHttpBinding> <binding name= ...

  2. JavaWeb学习——了解Servlet

    JavaWeb学习——了解Servlet 摘要:本文主要学习了什么是Servlet,以及如何使用Servlet进行开发. 基础知识 背景 随着互联网技术的发展,基于HTTP和HTML的web应用急速增 ...

  3. springboot~maven集成开发里的docker构建

    统一设计 maven很好的把项目整合在一起,在部署时,每个项目可以有自己的Dockerfile,在构建后把对应的jar包复制到Dockerfile的同级目录,使用使用统一的打包镜像和容器启动方法去执行 ...

  4. 搭建Nginx四层反向代理

    需求背景: 前段时间公司因为业务需求需要部署一个正向代理,我已经分享出来了https://www.cnblogs.com/Dfengshuo/p/11911406.html,现有因架构个更改,需要再加 ...

  5. SAP GUI Security notice

    出现错误提示: Failed to load administrator rule file.Check your Installation. 原因: 电脑缺少MS XML4.0,导致SAP客户端无法 ...

  6. 通过程序调用微信公众号发消息api返回48001

    自己的订阅号,尝试通过写程序来给用户发消息.结果呢,接口返回报错:errcode=48001,errmsg = api unauthorized hint: [ZlPULa02942276!] 去微信 ...

  7. 配置 yum 源的两种方法

    配置 yum 源的两种方法 由于 redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,重启安装,再配置其他源,以下为详细过程:  1.删除red ...

  8. jQuery仿京东首页广告图片切换图片轮播

    1.效果图如下: 2.源码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  9. 12C-使用跨平台增量备份减少可移动表空间的停机时间 (Doc ID 2005729.1)

    12C - Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (Doc ID 20057 ...

  10. 池化技术(二)HikariCP是如何管理数据库连接的?

    基于依赖程序的版本信息:HikariCP:3.3.1               驱动程序mysql-connector-java:8.0.17 上一篇:Druid是如何管理数据库连接的 零.类图和流 ...