Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
On an 8×8 chessboard, rows and columns are numbered 0 to 7, and squares are written (row, column). A knight moves in the usual L-shape (two squares in one direction and one square across). The knight may not land on the blocked squares (0,4), (0,5), (3,6), (5,1), (5,5), (6,3), (7,1). It starts at (1,7) and must reach (0,3). What is the minimum number of knight moves needed?
- A. 5
- B. 3
- C. 2
- D. 4
Correct answer: A. 5
A BFS that refuses blocked squares gives 5 moves. Ignoring the blocked squares gives 3, and treating the knight like a king gives 4.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Bellman–Ford is run from source X on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: F→I…
- A tree has the vertices C, E, G, K, N, S, T, V, Z and the edges T–K, K–E, K–V, K–S, S–N, N–C, C–G, G–Z. A centroid is a vertex whose…
- A grid has 3 rows and 3 columns with these values (top to bottom): 787 591 837 A path moves between side-adjacent cells (up, down, left or…
- Consider this function: python def g(n): if n < 3: return n if n % 2 == 0: return g(n - 3) + g(n - 2) return g(n - 1) - 1 What value does…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 1) if n % 2 == 0: f(n - 2) How many times is f called in total…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, with edges P1–Q2, P1–Q3, P1–Q1, P2–Q3. What is the size of a…