Treasure Hunter description You are in front of a cave that has treasures. The cave can represented in a grid which has rows numbered from 1 to , and of the columns numbered from 1 to . For this problem, define (?, ) is the tile that is in the -th row and -column. There is a character in each tile, which indicates the type of that tile. Tiles can be floors, walls, or treasures that are sequentially represented with the characters '.' (period), '#' (hashmark), and '*' (asterisk). You can pass floor and treasure tiles, but can't get past wall tiles. Initially, you are in a tile (??, ). You want to visit all the treasure squares, and take the treasure. If you visit the treasure chest, then treasure will be instantly taken, then the tile turns into a floor. In a move, if you are in a tile (?, ), then you can move to squares immediately above (? 1, ), right (?, + 1), bottom (? + 1, ), and left (?, 1) of the current plot. The tile you visit must not be off the grid, and must not be a wall patch. Determine the minimum number of steps you can take to take all the treasures treasure. Input Format The first line contains 3 integers, , , and . The second line contains 2 integers, and . Guaranteed that this plot is a plot floor. The next line contains characters. Characters in the -th row and -column represents the tile type. It is guaranteed that there are exactly characters of '*' in the grid. Output Format A line containing the minimum number of steps to retrieve all treasures. If You can't take all the treasures, take out 1. Example Input and Output Example Explanation In the first sample test case, you can perform the following sequence of steps: 1. walk left towards (1, 2) and pick up the treasure, 2. walk left towards (1,1) and pick up the treasure, 3. walk right towards (1, 2), 4. walk to the right towards (1, 3), 5. walk to the right towards (1, 4) and pick up the treasure, 6. walk right towards (1,5) and pick up the treasure, and 7. walk right towards (1, 6) and pick up the treasure You are asked to create an algorithm that can solve a given problem. Provide an analysis of why your algorithm is correct, and write down the time complexity of your algorithm Please make this two : a. Write the Algorithm b. Time Complexity of the Algorithm If can, also give code using C/C++
Treasure Hunter
description
You are in front of a cave that has treasures. The cave can
represented in a grid which has rows numbered from 1
to , and of the columns numbered from 1 to . For this problem, define (?, )
is the tile that is in the -th row and -column.
There is a character in each tile, which indicates the type of that tile.
Tiles can be floors, walls, or treasures that are sequentially represented
with the characters '.' (period), '#' (hashmark), and '*' (asterisk). You can pass
floor and treasure tiles, but can't get past wall tiles.
Initially, you are in a tile (??, ). You want to visit all the treasure squares, and
take the treasure. If you visit the treasure chest, then treasure
will be instantly taken, then the tile turns into a floor.
In a move, if you are in a tile (?, ), then you can move to
squares immediately above (? 1, ), right (?, + 1), bottom (? + 1, ), and left (?, 1) of the
current plot. The tile you visit must not be off the grid, and must not be a
wall patch.
Determine the minimum number of steps you can take to take all the treasures
treasure.
Input Format
The first line contains 3 integers, , , and .
The second line contains 2 integers, and . Guaranteed that this plot is a plot
floor.
The next line contains characters. Characters in the -th row and -column
represents the tile type. It is guaranteed that there are exactly characters of '*' in the grid.
Output Format
A line containing the minimum number of steps to retrieve all treasures. If
You can't take all the treasures, take out 1.
Example Input and Output
Example Explanation
In the first sample test case, you can perform the following sequence of steps:
1. walk left towards (1, 2) and pick up the treasure,
2. walk left towards (1,1) and pick up the treasure,
3. walk right towards (1, 2),
4. walk to the right towards (1, 3),
5. walk to the right towards (1, 4) and pick up the treasure,
6. walk right towards (1,5) and pick up the treasure, and
7. walk right towards (1, 6) and pick up the treasure
You are asked to create an
Provide an analysis of why your algorithm is correct, and write down the time complexity of
your algorithm
Please make this two :
a. Write the Algorithm
b. Time Complexity of the Algorithm
If can, also give code using C/C++
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images