青蛙跳跳;

package com.code;

public class Test03_1 {
public int solution(int X, int Y, int D) {
int res = (Y-X)/D+((Y-X)%D==0?0:1);
return res;
} public static void main(String[] args) {
Test03_1 t03 = new Test03_1();
System.out.println(t03.solution(10, 85, 30)); }
} /** A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position
greater than or equal to Y. The small frog always jumps a fixed distance, D. Count the minimal number of jumps that the small frog must perform to reach its target. Write a function: class Solution { public int solution(int X, int Y, int D); } that, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y. For example, given: X = 10
Y = 85
D = 30
the function should return 3, because the frog will be positioned as follows: after the first jump, at position 10 + 30 = 40
after the second jump, at position 10 + 30 + 30 = 70
after the third jump, at position 10 + 30 + 30 + 30 = 100
Assume that: X, Y and D are integers within the range [1..1,000,000,000];
X ≤ Y.
Complexity: expected worst-case time complexity is O(1);
expected worst-case space complexity is O(1).
*
*
*
*/

1. 青蛙跳跳FrogJmp Count minimal number of jumps from position X to Y.的更多相关文章

  1. [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 ...

  2. How to count the number of threads in a process on Linux

    If you want to see the number of threads per process in Linux environments, there are several ways t ...

  3. 2017年上海金马五校程序设计竞赛:Problem C : Count the Number (模拟)

    Description Given n numbers, your task is to insert '+' or '-' in front of each number to construct ...

  4. Count the number of possible triangles

    From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...

  5. OpenCV count the number of connected camera 检测连接的摄像头的数量

    有时候在项目中我们需要检测当前连接在机子上的摄像头的数量,可以通过下面的代码实现,其中连接摄像头的最大数量maxCamNum可以任意修改: /** * Count current camera num ...

  6. fatal error C1003: error count exceeds number; stopping compilation解决方法

    [error]C1003: error count exceeds 100; stopping compilation ...winnt.h 在项目工程中添加#include<windows.h ...

  7. FB面经prepare: Count the number of Vector

    给一个超级大的排好序的vector [abbcccdddeeee]比如,要求返回[{,a}, {,b}, {,c}, {,d}, {,e}......]复杂度要优于O(N) 分析: 如果是binary ...

  8. js错误: Unexpected number in JSON at position 2792 value里面有双引号怎么解决

    源头  出现这个报错提示,大家从错误就可以看的出来,这就是json的错误,一般来说都是json格式出现了错误,本人遇到比较多的情况就是json字符串里面出现了一些会影响json格式的符号,这次出现这个 ...

  9. Time complexity--codility

    lesson 3: Time complexity exercise: Problem: You are given an integer n. Count the total of 1+2+...+ ...

随机推荐

  1. Asp.net MVC中文件上传的参数转对象的方法

    参照博友的.NET WebApi上传文件接口(带其他参数)实现文件上传并带参数,当需要多个参数时,不想每次都通过HttpContext.Request.Params去取值,就针对HttpRequest ...

  2. [Windows Server 2003] 手工创建安全网站

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:手工创建安全站 ...

  3. day21-1 类的继承

    目录 类的继承 什么是继承 为什么用继承 对象的继承 继承与抽象 继承的应用 对象属性查找顺序 类的继承 什么是继承 继承是一种创建新类的方式,新建的类可以继承一个或多个父类(python支持多继承) ...

  4. axios方法get及post代码示例

    show: function(){ //get方式 //赋值给变量self var self = this; var url = "hotcity.json"; axios.get ...

  5. 01Hypertext Preprocessor

    Hypertext Preprocessor PHP即Hypertext Preprocessor是一种被广泛使用的开放源代码多用途动态交互性站点的强有力的服务器端脚本语言尤其适用于 Web开发人员可 ...

  6. 官方安装docker-ce步骤

    这里是Centos7安装方式 安装依赖包 $ sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 添加Docker ...

  7. java8 foreach不能使用break、countinue

    在学习1.8新特性的过程中,发现foreach中不可以使用break和countinue,然后我使用了return,结果如下图,对循环并没有影响. 百度一下,发现了一个不一样的回答 然后我就看了下源码 ...

  8. naca0012

    naca0012 naca0012 Table of Contents 1. NACA0012 lift and drag from 0-180 1.1. Data– Cl Cd vs. aoa 2. ...

  9. HDU 5178 pairs(双指针)

    HDU 5178 pairs(双指针) Hdu 5178 解法:因为要求的是绝对值小于等于k,因此数字的序号关系并不重要,那么排序后使用双指针即可解决这个问题. #include<queue&g ...

  10. c# 缓存!

    做项目的时候获取所有城市的时候,发现每次去获取都花费了很多时间,所以用缓存方法让效率更高! 这是我做的例子,如下: public class CacheGetCity { /// <summar ...