sliver__

Codility : Lesson 3 (Time complexity) - FrogJmp 본문

CS/Codility

Codility : Lesson 3 (Time complexity) - FrogJmp

sliver__ 2021. 9. 25. 16:29
728x90

안녕하세요~~

디벨롭퍼입니다~~~

오늘은 Lesson3 (Time complexity)  : FrogJmp 문제를 풀어보았습니다.

 

https://app.codility.com/programmers/lessons/3-time_complexity/frog_jmp/

 

FrogJmp coding task - Learn to Code - Codility

Count minimal number of jumps from position X to Y.

app.codility.com

***********************************************************************

풀어보실 분들을 위해서 링크 걸어두었습니다.

***********************************************************************

 

주어진 문제는 아래와 같습니다.

 

FrogJmp

 

시작점의 위치 : X

도착점의 위치 : Y

한번에 이동할 수 있는 거리 : D

위 3가지가 파라미터로 주어집니다.

 

X <= Y 인 개구리가 움직인 횟수를 구하는 문제입니다.

 

제출한 코드는 아래와 같습니다.

 

// you can use includes, for example:
// #include <algorithm>

// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;

int solution(int X, int Y, int D) {
    // write your code in C++14 (g++ 6.2.0)
    return ((Y-X) % D > 0) ? ((Y-X)/D + 1) : ((Y-X)/D);
}

 

다음 문제에서 만나요~~

그럼 이만~~~

728x90
Comments