Tap here to switch tabs
Problem
Submissions

Problem: Squirrel Simulation

Try to solve the Squirrel Simulation problem.

Statement

You are given two integers height and width representing a grid of size height $ imes$ width. You are also given an integer array tree of length 22 representing the coordinates of a tree, an integer array squirrel of length 22 representing the starting coordinates of a squirrel, and an array of integer arrays nuts where each nuts[i] represents the coordinates of a nut.

The squirrel can carry at most 11 nut at a time and travels across the grid where moving 11 cell horizontally or vertically costs 11 unit of distance. The distance between any two positions (r1,c1)(r_1, c_1) and (r2,c2)(r_2, c_2) is given by the Manhattan distance ∣r1−r2∣+∣c1−c2∣|r_1 - r_2| + |c_1 - c_2|.

Return the minimum total distance the squirrel must travel to collect all the nuts and bring them to the tree one by one.

Constraints:

  • 1≤1 \leq height, width ≤100\leq 100

  • tree.length =2= 2

  • squirrel.length =2= 2

  • 1≤1 \leq nuts.length ≤5000\leq 5000

  • nuts[i].length =2= 2

  • 0≤0 \leq tree_r, squirrel_r, nut_{ir} ≤\leq height

  • 0≤0 \leq tree_c, squirrel_c, nut_{ic} ≤\leq width

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Squirrel Simulation

Try to solve the Squirrel Simulation problem.

Statement

You are given two integers height and width representing a grid of size height $ imes$ width. You are also given an integer array tree of length 22 representing the coordinates of a tree, an integer array squirrel of length 22 representing the starting coordinates of a squirrel, and an array of integer arrays nuts where each nuts[i] represents the coordinates of a nut.

The squirrel can carry at most 11 nut at a time and travels across the grid where moving 11 cell horizontally or vertically costs 11 unit of distance. The distance between any two positions (r1,c1)(r_1, c_1) and (r2,c2)(r_2, c_2) is given by the Manhattan distance ∣r1−r2∣+∣c1−c2∣|r_1 - r_2| + |c_1 - c_2|.

Return the minimum total distance the squirrel must travel to collect all the nuts and bring them to the tree one by one.

Constraints:

  • 1≤1 \leq height, width ≤100\leq 100

  • tree.length =2= 2

  • squirrel.length =2= 2

  • 1≤1 \leq nuts.length ≤5000\leq 5000

  • nuts[i].length =2= 2

  • 0≤0 \leq tree_r, squirrel_r, nut_{ir} ≤\leq height

  • 0≤0 \leq tree_c, squirrel_c, nut_{ic} ≤\leq width