Mr. Gorilla, a muscular man, has gotten lost in a maze. The maze is a rectangle...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Mr. Gorilla, a muscular man, has gotten lost in a maze. The maze is a rectangle of n rows and m columns, and it consists of open spaces and walls. Mr. Gorilla starts at positions and he wants to go to position G. Both s and G are open spaces. Mr. Gorilla can move in four directions, up, down, left, and right. The time it takes to move is determined in this way: • If the position he's trying to move into is not a wall, it takes one second. • If the position he's trying to move into is a wall, he breaks down the wall because he is so strong and moves into the new space that was occupied by the wall before he broke it down. However, each wall he breaks down makes him more tired, so he must rest a seconds after breaking down each wall, where is the total number of walls he has broken down prior to that wall. Moreover, it takes one more second to actually move into the new space. Mr. Gorilla is not good at working with his brain. Therefore, implement a program which calculates for Mr. Gorilla the minimum amount of time needed for him to move from positions to position G. The mission You are given a maze. Calculate the minimum amount of time needed for Mr. Gorilla to move from positions to position Implementation CLI Implement a command line application that receives standard input and writes the answer to its standard output. For details, see the "Command line application template" section at the bottom of the page. Input rules Your CLI program should receive standard input. ./myApp The format of the standard input is as below: n m 81 Sn The conditions are as follows: 2 <n, m < 30, integer • s; is a string whose length is m • Consists of only s, G, 0 s denotes the position Mr. Gorilla starts from G denotes the destination of Mr. Gorilla 0 0 . 0 # denotes a wall s and G are always open spaces The following additional condition is satisfied for 30% of all test cases. There are no walls in the given maze . answer denotes an open space Output rule Your CLI program should write the answer to its standard output. The format of the standard output is as below: Standard output On the 1st line, print the minimum time needed for Mr. Gorilla to move from positions to position G. Input & Output examples Example 1 Standard input (00_samplel.in) 3 3 S## ##. #.G Standard output 5 Let's call the position of the ith row and the jth column the point (i, j) (1 ≤ i ≤n, 1<j<m). Mr. Gorilla can reach the destination in 5 seconds by moving in the following way: • At first Mr. Gorilla is at point (1, 1). • He breaks down the wall at point (2, 1) and moves into the space. As he has broken no other walls yet, it takes 0 seconds to break this wall. It takes 1 second to move. • He breaks down the wall at point (2, 2) and moves into the space. As he broke 1 wall previously, it takes 1 second to break this wall. It also takes 1 second to move. • He moves to point (2, 3). This takes 1 second. • He moves to point (3, 3). This takes 1 second. Example 2 Standard Input (00_sample2.in) 3 3 S## He reaches his destination. ### ..G Standard Output 4 . Mr. Gorilla starts at point (1, 1). • He breaks down the wall at point (2, 1) and moves into the space. As he has broken no walls previously to this wall, it takes 0 seconds to break this wall. It takes 1 second to move. • He moves to point (3, 1). It takes 1 second. • He moves to point (3, 2). It takes 1 second.. He moves to point (3, 3). It takes 1 second.. He reaches his destination. . Example 3 Standard Input (00_sample3.in) 5 3 ... ..S Standard Output 3. This test case satisfies the conditions of the simple test cases because the maze has no walls. • Mr. Gorilla starts at point (2, 3). • He moves to point (2, 2). This takes 1 second. • He moves to point (3, 2). This takes 1 second. • He moves to point (4,2). This takes 1 second. He reaches his destination. . There are other input & output examples defined in this file: test/basic_testcases.json You can use it as a reference while working on this exercise. Command line application template for C Implement CLI application by editing main.c. You may add new files to keep your code clean, if it is allowed in your challenge. How to get stdin lines You can use scanf, fget, etc. The template has sample code which using fget. You can modify that code as you like. How to output result How to output result You can use printf printf ("argv[i]: %s\n", i, argv[i]); How to compile To compile, we are using clang gcc command. If you want to change compile option or etc, please edit makefile. Mr. Gorilla, a muscular man, has gotten lost in a maze. The maze is a rectangle of n rows and m columns, and it consists of open spaces and walls. Mr. Gorilla starts at positions and he wants to go to position G. Both s and G are open spaces. Mr. Gorilla can move in four directions, up, down, left, and right. The time it takes to move is determined in this way: • If the position he's trying to move into is not a wall, it takes one second. • If the position he's trying to move into is a wall, he breaks down the wall because he is so strong and moves into the new space that was occupied by the wall before he broke it down. However, each wall he breaks down makes him more tired, so he must rest a seconds after breaking down each wall, where is the total number of walls he has broken down prior to that wall. Moreover, it takes one more second to actually move into the new space. Mr. Gorilla is not good at working with his brain. Therefore, implement a program which calculates for Mr. Gorilla the minimum amount of time needed for him to move from positions to position G. The mission You are given a maze. Calculate the minimum amount of time needed for Mr. Gorilla to move from positions to position Implementation CLI Implement a command line application that receives standard input and writes the answer to its standard output. For details, see the "Command line application template" section at the bottom of the page. Input rules Your CLI program should receive standard input. ./myApp The format of the standard input is as below: n m 81 Sn The conditions are as follows: 2 <n, m < 30, integer • s; is a string whose length is m • Consists of only s, G, 0 s denotes the position Mr. Gorilla starts from G denotes the destination of Mr. Gorilla 0 0 . 0 # denotes a wall s and G are always open spaces The following additional condition is satisfied for 30% of all test cases. There are no walls in the given maze . answer denotes an open space Output rule Your CLI program should write the answer to its standard output. The format of the standard output is as below: Standard output On the 1st line, print the minimum time needed for Mr. Gorilla to move from positions to position G. Input & Output examples Example 1 Standard input (00_samplel.in) 3 3 S## ##. #.G Standard output 5 Let's call the position of the ith row and the jth column the point (i, j) (1 ≤ i ≤n, 1<j<m). Mr. Gorilla can reach the destination in 5 seconds by moving in the following way: • At first Mr. Gorilla is at point (1, 1). • He breaks down the wall at point (2, 1) and moves into the space. As he has broken no other walls yet, it takes 0 seconds to break this wall. It takes 1 second to move. • He breaks down the wall at point (2, 2) and moves into the space. As he broke 1 wall previously, it takes 1 second to break this wall. It also takes 1 second to move. • He moves to point (2, 3). This takes 1 second. • He moves to point (3, 3). This takes 1 second. Example 2 Standard Input (00_sample2.in) 3 3 S## He reaches his destination. ### ..G Standard Output 4 . Mr. Gorilla starts at point (1, 1). • He breaks down the wall at point (2, 1) and moves into the space. As he has broken no walls previously to this wall, it takes 0 seconds to break this wall. It takes 1 second to move. • He moves to point (3, 1). It takes 1 second. • He moves to point (3, 2). It takes 1 second.. He moves to point (3, 3). It takes 1 second.. He reaches his destination. . Example 3 Standard Input (00_sample3.in) 5 3 ... ..S Standard Output 3. This test case satisfies the conditions of the simple test cases because the maze has no walls. • Mr. Gorilla starts at point (2, 3). • He moves to point (2, 2). This takes 1 second. • He moves to point (3, 2). This takes 1 second. • He moves to point (4,2). This takes 1 second. He reaches his destination. . There are other input & output examples defined in this file: test/basic_testcases.json You can use it as a reference while working on this exercise. Command line application template for C Implement CLI application by editing main.c. You may add new files to keep your code clean, if it is allowed in your challenge. How to get stdin lines You can use scanf, fget, etc. The template has sample code which using fget. You can modify that code as you like. How to output result How to output result You can use printf printf ("argv[i]: %s\n", i, argv[i]); How to compile To compile, we are using clang gcc command. If you want to change compile option or etc, please edit makefile.
Expert Answer:
Answer rating: 100% (QA)
Here i am using a small logic that is first i have to fond the ... View the full answer
Related Book For
Discrete and Combinatorial Mathematics An Applied Introduction
ISBN: 978-0201726343
5th edition
Authors: Ralph P. Grimaldi
Posted Date:
Students also viewed these programming questions
-
An owner decides that he wants to go ahead with manufacturing; he must spend $900,000 for the new equipment, legal fees of $50,000, start-up cost, $50,000. The formula will net the company an...
-
In an amusement park maze with all the walls covered with mirrors, Pilar sees Hernando's reflection from a series of three mirrors. If the reflected angle from mirror 3 is 55 ° for the mirror...
-
For the following program segment, m and n are integer variables. The variable A is a two-dimensional array A[1, 1], A[1, 2], . . . , A[1, 20], . . ., A[10, 1], . . . , A[10, 20], with 10 rows...
-
The slurry of Prob. 29.3 is to be filtered in a press having a total area of 8 m 2 and operated at a constant pressure drop of 2 atm. The frames are 36 mm thick. Assume that the filter medium...
-
Define direct materials and indirect materials. List reasons that a large company would have two separate departments to manage the purchasing activities for each.
-
Casablanca Furniture wishes to establish a prearranged borrowing agreement with a local commercial bank. The bank's terms for a line of credit are 3.30 percent over the prime rate, and each year the...
-
What are the resistances \(R\) and the emf of the battery in Figure P23.23? E ww R 3.0 A 2.0 A FIGURE P23.23 wwww R 102
-
A Soprano Electric sold $3,000,000, 10%, 10-year bonds on January 1, 2010. The bonds were dated January 1 and pay interest July 1 and January 1. Soprano Electric uses the straight line method to...
-
2) Value of the Energy Gel Project. Should HPC pursue the Energy Gel market? To answer this question, you need to consider how a firm should make investment decisions. HPC uses several metrics when...
-
Snowden Industries produces two electronic decoders, P and Q. Decoder P is more sophisticated and requires more programming and testing than does Decoder Q. Because of these product differences, the...
-
The following table gives a two-way classification of all basketball players at a state university who began their college careers between 2004 and 2008, based on gender and whether or not they...
-
Define the study of group dynamics and discuss why it is important for healthcare leaders to understand and be aware of these dynamics.
-
A lottery jackpot of one million is paid out RM25,000 a year for 40 years. At a 10 percent required return, what is the present value of this payoff? Assume that the first payment is paid immediately.
-
A few states still apply the traditional rule of contributory negligence, under which any amount of negligence by the plaintiff is an absolute bar to recovery. Are there any advantages to that...
-
A startup raises 5 million and ends up with a 30 million post-money valuation. What is the startup's pre-money valuation?
-
What is a risk management framework and why it should be linked to other business processes? As a Consultant illustrates how poor stakeholder's engagement on a Cervical & Prostate Screening Project...
-
APPLY YOUR SKILLS 6-1 Catch Up on Transactions you will be catching up on Melanie's bookkeeping and will complet any outstanding recurring transactions and make bill payments and receive payments to...
-
Read the following description and Write a response of it. The discretion of public administrators can be decreased, but not altogether eliminated. Officials will use their discretion in any given...
-
Let G = (V, E) be a loop-free undirected graph. We call G color-critical if x(G) > x(G - v) for all v V. (a) Explain why cycles with an odd number of vertices are color-critical while cycles with an...
-
In the following program segment i, j, m, and n are integer variables. The values of m and n are supplied by the user earlier in the execution of the total program. for i : = 1 to m do for j : = 1 to...
-
(a) In how many ways can 10 people, denoted A, B, I, J, be seated about the rectangular table shown in Fig. 1.11, where Figs. 1.11 (a) and 1.11(b) are considered the same but are considered different...
-
Novo Nordisk is a Denmark-based biopharmaceutical company with a focus on diabetes drugs. The company provides detailed disclosure of revenue along geographic, business segment, and product lines....
-
Use the data in Example 1 on Novo Nordisk to answer the following questions: i. Xiaoping Wu is an equity analyst covering European pharmaceutical companies for his clients in China. Wu projects that...
-
Walgreens and Rite Aid are two of the largest retail drugstore chains in the United States. For both companies, around two-thirds of their sales are from prescription pharmaceuticals, with the...
Study smarter with the SolutionInn App