interviewbit :Min Steps in Infinite GridBookmark Suggest Edit
You are in an infinite 2D grid where you can move in any of the 8 directions :
(x,y) to
(x+1, y),
(x - 1, y),
(x, y+1),
(x, y-1),
(x-1, y-1),
(x+1,y+1),
(x-1,y+1),
(x+1,y-1)
You are given a sequence of points and the order in which you need to cover the points. Give the minimum number of steps in which you can achieve it. You start from the first point.
Example :
Input : [(0, 0), (1, 1), (1, 2)]
Output : 2
It takes 1 step to move from (0, 0) to (1, 1). It takes one more step to move from (1, 1) to (1, 2).
This question is intentionally left slightly vague. Clarify the question by trying out a few cases in the “See Expected Output” section.
public class Solution {
// X and Y co-ordinates of the points in order.
// Each point is represented by (X.get(i), Y.get(i))
public int coverPoints(ArrayList<Integer> X, ArrayList<Integer> Y) {
int x=0;
int i,j,k;
for(i=1;i<X.size();++i){
j=Math.abs(X.get(i)-X.get(i-1));
k=Math.abs(Y.get(i)-Y.get(i-1));
x+=(j>k)?j:k;
}
return x;
}
}
interviewbit :Min Steps in Infinite GridBookmark Suggest Edit的更多相关文章
- interviewbit : Max Non Negative SubArrayBookmark Suggest Edit
Find out the maximum sub-array of non negative numbers from an array.The sub-array should be continu ...
- 利用CSS3 中steps()制用动画
.monster { width: 190px; height: 240px; margin: 2% auto; background: url('http://treehouse-code-samp ...
- 深入理解CSS3 animation的steps
在应用 CSS3 渐变/动画时,有个控制时间的属性 <timing-function> .它的取值中除了常用到的三次贝塞尔曲线以外,还有个让人比较困惑的 steps() 函数. steps ...
- 经常被忽略的几个CSS3属性之强大应用(一、timing-function: steps() 二、animation-direction 三、timing-function: cubic-bezier())
一.timing-function: steps() 一开始在使用CSS3的时候并没有太注意这个timing-function,只是注意到自定义贝塞尔曲线. 1)一个项目中的实例 先来看看左边加了st ...
- CSS3 animation的steps方式过渡
animation默认以ease方式过渡,它会在每个关键帧之间插入补间动画,所以动画效果 是连贯性的.除了ease,linear.cubic-bezier之类的过渡函数都会为其插入补间. 但有些效果不 ...
- 浅谈CSS3动画的凌波微步--steps()
背景 一日敲代码的我,得到一个需求:写一个10秒的倒计时. 用JavaScript定时器麻溜写完之后,恰好同事勇司机接完水.瞟了一眼,然后凑过来说,这个用CSS3也可以写,而且一行JavaScript ...
- CSS3 animation-timing-function steps()
animation-timging-function 主要是控制css动画从开始到结束的速度. linear:线性过渡.等同于贝塞尔曲线(0.0, 0.0, 1.0, 1.0) ease:平滑过渡.等 ...
- 过渡与动画 - steps调速函数&CSS值与单位之ch
写在前面 上一篇中我们熟悉五种内置的缓动曲线和(三次)贝塞尔曲线,并且基于此完成了缓动效果. 但是如果我们想要实现逐帧动画,基于贝塞尔曲线的调速函数就显得有些无能为力了,因为我们并不需要帧与帧之间的过 ...
- 用animation的steps属性制作帧动画
昨天火急火燎地接到一个任务,说是要做一个掷骰子的游戏,关于掷骰子期间的过渡动画,我本来是想用css 3d制作一个立体的骰子,然后叫UI给6张平面图贴上去.再用translate3d来操作.然而UI考虑 ...
随机推荐
- POC - ASP.NET & MYSQL部分
1. ASP.NET 用MYSQL是需要引入MYSQL的包的,这个在VS的TOOLS-> extension manager里可以搜到的 2. 接下来是WEBCONFIG里的配置信息 <c ...
- GCC编译默认的头文件搜索路径
对于c语言来说: gcc -xc -E -v - 截图: 对于c++来说: gcc -xc++ -E -v - 截图: gcc的arg和opt解释: 后面一干啥作用暂时不知道
- “我爱淘”冲刺阶段Scrum站立会议9
完成任务: 完成了webservice的配置与测试. 计划任务: 可以通过webservice将数据库中的内容解析出来,通过查询可以得到想要的内容. 遇到问题: 服务器已经配好,,也已经测试成功,不过 ...
- Phantom omini设备开发流程
最近在忙着做毕业设计,我的毕业设计是做力觉临场感的,所以在力反馈设备Phantom Omini,由于整个设备是国外的国内的资料很少,我是14年拿到这个设备的但是真的是在开发是在16年了,中间有很多事没 ...
- C#委托详解(2):实现方式大全
本系列文章将详细探讨C#中的委托,列举其主要的实现方式,并分析其在设计层面和编码层面带来的好处,最后会讨论其安全性和执行效率等. 接上篇(C#委托详解(1):什么是委托)介绍完什么是委托之后,来看看C ...
- 【LRU Cache】cpp
题目: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the ...
- 使用Java Service Wrapper在Linux下配置Tomcat应用
前言 Java Service Wrapper是Tanuki Software的一个产品,可以将Java应用注册成Windows或Linux服务,使其可以随系统开机启动,同时可以监控Java应用的状态 ...
- 【BZOJ】【2178】圆的面积并
自适应辛普森积分 Orz Hzwer 辛普森真是个强大的东西……很多东西都能积= = 这题的正解看上去很鬼畜,至少我这种不会计算几何的渣渣是写不出来……(对圆的交点求图包,ans=凸包的面积+一堆弓形 ...
- nginx+php+flight 构建RESTFul API
配置: Nginx: conf目录下nginx.conf配置文件. 第44行改为:root D:/wwwroot/www; 第45行改为:index index.html index.htm i ...
- [geeksforgeeks] Count the number of occurrences in a sorted array
Count the number of occurrences in a sorted array Given a sorted array arr[] and a number x, write a ...