Git Product home page Git Product logo

superknight-cpp's Introduction

SuperKnight


A rectangular board is divided into M rows and N columns (2 <= M, N <= 100). A SuperKnight jumps from one square x to another square y as follows: from x, it moves p squares, either horizontally or vertically, and then it moves q squares in a direction perpendicular to the previous to get to y. It can move horizontally either to the left or to the right and vertically either up or down. (A SuperKnight move is similar to a knight move in chess with p = 2 and q = 1).

Assume that the top-left square is (1, 1) and the bottom-right square is (M, N). The SuperKnight is put in the square with coordinates (X, Y) (1 <= X <= M, 1 <= Y <= N). The SuperKnight wishes to get to a different square (U, V) (1 <= U <= M, 1 <= V <= N) using only the jumps described above. It is required to find the minimal number, S, of jumps needed to get to (U, V) and the sequence of squares visited in reaching (U, V). If there is more than one sequence, you need find only one. If it is not possible to get to (U, V) from (X, Y), print an appropriate message. For example, consider a board with 7 rows and 4 columns, with p = 2, q = 1. Suppose the SuperKnight starts in square (3, 1) and it needs to get to square (6, 1). It can do so in 3 moves by jumping to (5, 2) then (7, 3) then (6, 1). Write a program which reads values for M, N, p, q, X, Y, U, V in that order and prints the minimum number of moves followed by the squares visited or a message that the SuperKnight cannot get to the destination square from the starting one.

Sample input

7 4 2 1 3 1 6 1

Sample output

3

(3, 1)

(5, 2)

(7, 3)

(6, 1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.