0% found this document useful (0 votes)
218 views4 pages

Problem H Binus

This document describes an algorithm problem to determine if two knights, one black and one white, placed on a chessboard can meet within a limited number of moves. The input provides the number of test cases, movement limit, and starting positions of each knight per test case. The output should state "YES" if the knights can meet or "NO" if they cannot within the given parameters. Recursive techniques are suggested to solve the problem. Constraints on the input values and sample input/output are also provided.

Uploaded by

Rudi Rahantio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
218 views4 pages

Problem H Binus

This document describes an algorithm problem to determine if two knights, one black and one white, placed on a chessboard can meet within a limited number of moves. The input provides the number of test cases, movement limit, and starting positions of each knight per test case. The output should state "YES" if the knights can meet or "NO" if they cannot within the given parameters. Recursive techniques are suggested to solve the problem. Constraints on the input values and sample input/output are also provided.

Uploaded by

Rudi Rahantio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

COMP6047 – Algorithm and Programming

White and Black Horse


Lili was very glad when playing chess. She also very interested especially on knight piece.
The, she decided to find some fact from the knight piece. Apparently, the ”black” knight
and ”white” knight are couple. Because Lili knows the truth, she will try to bring them
together. But because Lili is a beginner player in chess, she can only run each piece N
times.

Help Lili find out whether the two knights (the white and the black one) can meet to-
gether or not.

You are encouraged to use recursive techniques to solve this problem.

Format Input
Input consists of 1 integer T indicating number of testcase and followed by 3T row after.
For each test case, the first line contains N , number of step limitation in this game. The
second line contains the coordinate (in chessboard) x1 , y1 , location of the ”black” knight.
The third line contains the coordinate (in chessboard) x2 , y2 , location of the ”white”
knight. Coordinates will be expressed in letter and number form (e.g. A5, A2, C1).

Format Output
Output should be expressed in format ”Case #X: Y” - X is number of testcase and Y is
the answer ”YES” if those two knights can meet together and ”NO” if they can not meet
together (without quotes).

c School of Computer Science - BINUS, 2019. No part of the materials available may be copied,
photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form,
in whole or in part, without prior written consent of School of Computer Science - BINUS. Any other
reproduction in any form without the permission of School of Computer Science - BINUS is probihited.
For those who violated this disclaimer, academic sanctioned can be enforced.
COMP6047 – Algorithm and Programming

Constraints
• 1 ≤ T, N ≤ 10

• A ≤ x1 , x2 ≤ H

• 1 ≤ y1 , y2 ≤ 8

Sample Input (standard input)


2
3
A1 H8
1
H1 A8

Sample Output (standard output)


Case #1: YES
Case #2: NO

Explanation
The possible way for them to meet each other described on the figure above. Steps for
the ”black” knight is colored yellow and for the ”white” knight is colored red. Finally,
they meet together in a purple area.

Note
For this problem, there are many possibilities those knights can meet at various points.
So as long as they can meet together, the output will be ”YES”, even though there is
only 1 valid point.

c School of Computer Science - BINUS, 2019. No part of the materials available may be copied,
photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form,
in whole or in part, without prior written consent of School of Computer Science - BINUS. Any other
reproduction in any form without the permission of School of Computer Science - BINUS is probihited.
For those who violated this disclaimer, academic sanctioned can be enforced.
COMP6047 – Algorithm and Programming

White and Black Horse


Lili sangat senang bermain catur, dan ia sangat tertarik pada bidak-bidak catur, khusus-
nya bidak kuda. Ia pun mencari tahu asal usul dari kuda tersebut. Ternyata, kuda hitam
dan kuda putih merupakan sepasang kekasih. Karena Lili mengetahui kebenaran itu,
ia pun akan berusaha untuk mempertemukan mereka berdua. Namun karena Lili baru
dalam permainan catur, ia hanya dapat menjalankan masing-masing bidak sebanyak N
kali.

Bantulah Lili dalam mencari tahu apakah kedua kuda tersebut dapat bertemu atau tidak.

Anda disarankan untuk menggunakan teknik rekursif untuk menyelesaikan


masalah ini.

Format Input
Input terdiri dari 1 buah angka bulat T yang menyatakan jumlah testcase dan diikuti
oleh 3T baris. Pada tiap kasus, baris pertama terdapat N , batas jalan dari setiap bidak.
Baris kedua berisi koordinat x1 , y1 , lokasi dari kuda hitam. Baris ketiga berisi koordinat
x2 , y2 , lokasi dari kuda putih. Koordinat akan dinyatakan dalam huruf dan angka (contoh
: A5, A2, C1).

Format Output
Output yang dikeluarkan dalam format ”Case #X: Y” - X merupakan nomor testcase dan
Y merupakan jawaban ”YES” apabila kedua kuda tersebut dapat bertemu, dan ”NO”
apabila tidak mungkin kedua tersebut bertemu (jawaban tanpa tanda petik).

c School of Computer Science - BINUS, 2019. No part of the materials available may be copied,
photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form,
in whole or in part, without prior written consent of School of Computer Science - BINUS. Any other
reproduction in any form without the permission of School of Computer Science - BINUS is probihited.
For those who violated this disclaimer, academic sanctioned can be enforced.
COMP6047 – Algorithm and Programming

Constraints
• 1 ≤ T, N ≤ 10

• A ≤ x1 , x2 ≤ H

• 1 ≤ y1 , y2 ≤ 8

Sample Input (standard input)


2
3
A1 H8
1
H1 A8

Sample Output (standard output)


Case #1: YES
Case #2: NO

Explanation
Langkah yang dapat ditempuh kedua kuda di atas adalah seperti pada gambar. Kuda
hitam menempuh jalan kuning, kuda putih menempuh jalan yang merah, dan mereka
bertemu di kotak yang berwarna Ungu.

Note
Pada soal ini, ada berbagai kemungkinan kuda dapat bertemu di berbagai titik dan
selama mereka dapat bertemu, hasil outputnya adalah ”YES”, meskipun hanya ada 1
titik yang memenuhi.

c School of Computer Science - BINUS, 2019. No part of the materials available may be copied,
photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form,
in whole or in part, without prior written consent of School of Computer Science - BINUS. Any other
reproduction in any form without the permission of School of Computer Science - BINUS is probihited.
For those who violated this disclaimer, academic sanctioned can be enforced.

You might also like