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 r seconds after breaking down each wall, where z 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 position s to position G. The mission You are given a maze. Calculate the minimum amount of time needed for Mr. Gorilla to move from position s to position G. 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 S1 Sn The conditions are as follows: 2 <n, m < 30, integer • S; is a string whose length is m o Consists of only s. G, s denotes the position Mr. Gorilla starts from 6 denotes the destination of Mr. Gorilla denotes an open space # 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 Output rule Your CLI program should write the answer to its standard output. The format of the standard output is as below: Standard output answer On the 1st line, print the minimum time needed for Mr. Gorilla to move from position s 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 <isn,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. • He reaches his destination. Example 2 Standard Input ( 00_sample2.in ) 3 3 S## ### .. 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 ... .G. ... 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 r seconds after breaking down each wall, where z 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 position s to position G. The mission You are given a maze. Calculate the minimum amount of time needed for Mr. Gorilla to move from position s to position G. 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 S1 Sn The conditions are as follows: 2 <n, m < 30, integer • S; is a string whose length is m o Consists of only s. G, s denotes the position Mr. Gorilla starts from 6 denotes the destination of Mr. Gorilla denotes an open space # 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 Output rule Your CLI program should write the answer to its standard output. The format of the standard output is as below: Standard output answer On the 1st line, print the minimum time needed for Mr. Gorilla to move from position s 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 <isn,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. • He reaches his destination. Example 2 Standard Input ( 00_sample2.in ) 3 3 S## ### .. 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 ... .G. ... 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
Physics
ISBN: 978-0077339685
2nd edition
Authors: Alan Giambattista, Betty Richardson, Robert Richardson
Posted Date:
Students also viewed these algorithms questions
-
Need help with C programming. Write code to do allowing you to store these smaller floating point numbers in a 32-bit integer. INPUT: you will read in a program and call your functions to implement...
-
I need help with code for a LED cyclone light game.
-
JW's Lock & Key had the following transactions in December. Dec. 1 Paid December's rent, check & 6267, $2.000. 2 Paid annual premiums on property and casualty insurance policies, check 6288, $3,600 3...
-
The Sales Discounts account is a contra account to which of the following accounts? Cost of Goods Sold Sales Returns and Allowances Purchases Discounts Sales Revenue
-
Is it reasonable to hold principals responsible for contracts formed with only apparent authority? What are the tradeoffs?
-
Calculate the accumulated value in an RRSP account after 15 years under each of the following scenarios: (a) $2400 is invested annually at 10% compounded annually; (b) $600 is invested quarterly at...
-
The strategy for success at Sassy Jeans calls for rapid growth, a limited number of units for each design to enhance exclusivity, perfect fit, on-time delivery to customers, retaining employees who...
-
Tombert Decorating uses a job order cost system to collect the costs of its interior decorating business. Each clients consultation is treated as a separate job. Overhead is applied to each job based...
-
CASE STUDY; Acceptance Rule of IRR IRR will accept a venture if its IRR is higher than or equal to the minimum required rate of return which is usually the cost of finance also known as the cut off...
-
Champion Inc. purchased a call option as a speculative investment on January 1 for $125, allowing Champion Inc. to purchase 200 of Rising Star Co. common shares at $100 per share through January 1 of...
-
Digues quina es la resposta correcte: Respecte a la funci de versemblana a. s el resultat del multiplicatori la funci de quanta de probabilitat valorat a cada element de la mostra, tant de variables...
-
What are fractional share rights and why are they sometimes issued in connection with a stock dividend?
-
Explain the difference between cumulative and non-cumulative preferred shares, and the difference between non-participating, partially participating, and fully participating preferred shares.
-
a. What is involved in executing a sampling plan? b. Give several examples of deviations from prescribed controls.
-
What is the effect on assets, liabilities, and shareholders' equity of the (a) purchase of treasury stock and (b) sale of treasury stock?
-
If a shareholder donates a valuable piece of art to a company, to be displayed in the company boardroom, does the company record a gain on the transaction?
-
Hester opera un servicio de lavado de autos a mano y cobra a losclientes $10 por lavado de autos. Con base en su conocimiento delas operaciones, lavar el auto nmero 100 en un da le cuesta$9.95. 1...
-
A company produces earbuds. The revenue from the sale of x units of these earbuds is R = 8x. The cost to produce x units of earbuds is C = 3x + 1500. In what interval will the company at least break...
-
In a reciprocating saw, a Scotch yoke converts the rotation of the motor into the back-and-forth motion of the blade. The Scotch yoke is a mechanical device used to convert oscillatory motion to...
-
An RC filter is shown. The filter resistance R is variable between 180 and 2200 and the filter capacitance is C = 0.086 F. At what frequency is the output amplitude equal to 1/ 2 times the input...
-
(a) Show that it was valid to ignore the gravitational force in Problem 97. In problem 97 A negatively charged particle of mass 5.00 1019 kg is moving with a speed of 35.0 m/s when it enters the...
-
B Arkwright started in business on 1 January 19X5 with 10,000 in a bank account. Unfortunately he did not keep proper books of account. He is forced to submit a calculation of profit for the year...
-
A J Kirkwood is a dealer who has not kept proper books of account. At 31 August 19X6 his state of affairs was as follows: During the year to 31 August 19X7 his drawings amounted to 7,560. Winnings...
-
25.4 P Balance Sheet as at 31 December 19X5 Investment in S: 30,000 shares bought 31.12.19X4 53,400 Fixed assets 60,000 Less Depreciation for year 6,000 54,000 Current assets 10,600 118,000 Share...
Study smarter with the SolutionInn App