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++

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
1st Edition
ISBN:9780357392676
Author:FREUND, Steven
Publisher:FREUND, Steven
Chapter4: Financial Functions, Data Tables, And Amortization Schedules
Section: Chapter Questions
Problem 8AYK
icon
Related questions
Question

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++

Contoh Masukan
Contoh Keluaran
165
7
| 13
*****
552
21
#####
...#
#.#*#
#*.#
#####
574
19
12
#.#####
#*...*#
#.####
##.#.#
#.#
#*.#.*#
#####
352
-1
12
#.###
#*#*#
#####
Transcribed Image Text:Contoh Masukan Contoh Keluaran 165 7 | 13 ***** 552 21 ##### ...# #.#*# #*.# ##### 574 19 12 #.##### #*...*# #.#### ##.#.# #.# #*.#.*# ##### 352 -1 12 #.### #*#*# #####
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L