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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education