Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

solve this code for me please: Objective Give additional practice with Dynamic Memory Allocation in C . Give practice with Array Lists in C .

solve this code for me please: Objective
Give additional practice with Dynamic Memory Allocation in C.
Give practice with Array Lists in C.
Give practice with Stacks in C.
Give practice with grids in C.
Story
It looks like the wrong bait was used to attract the raccoons. The
bait used was watermelons and now there are a bunch of
elephants running amok around town. You have offered your
service to help determine the location of the elephants.
The town can be modeled as a 2 dimensional grid of R by C
intersections. You know of the initial location of every elephant
in town as required of your job as the IT specialist of the KAT
pet shop. The employees not wanting to get in any furth trouble
have finally given you the full information as to where and when
the baits were placed.
The elephants are lazy but greedy and at each hour they will move to the adjacent intersection
with the most number of watermelons. If there are more watermelons in their current location
than any adjacent intersection, then the elephant will stay where it is located. Once all the
elephants have reached their desired intersection, they will eat all the watermelons present if
any. If no location has watermelons they begin to walk back to their starting location, but only by
retracing their steps.
Elephants have a really good memory and they will remember all the directions they took to get
to where they are currently located. However, elephants are not the brightest. and will retrace
their steps even if it will take them eventually to the same location they are currently located. For
example if an elephant moves North to eat some watermelons, and in the next hour moves
South to eat some watermelons, when the elephant decides to return home, they will move
North in the first hour and South in the second hour ending up in their initial location.
Your bosses are concerned that some of the elephants might have consumed too many
watermelons too quickly. To help them monitor the watermelon intake you want to print how
much watermelon was consumed in each hour.
Problem
You will be given the initial locations of all the elephants, and a series of commands
representing the occurrence of the change of an hour or the placement of bait. You need to
determine the amount of bait consumed at each hour and the ending locations for all the
elephants.
Input
The first line of input will contain a single integer, N(1N10,000), representing the number of
elephants to track. The following N lines will each contain the initial location of the
corresponding elephant as 2 integers, R and C(1R,C500), representing the row and
column of the location in the grid.
Following this will be a series of command in one of the following 3 formats,
BAIT R C A
Which represents A additional watermelons placed at the R-th row and the C-th
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Apache Cassandra 3 X An Expert Guide To Improving Database Scalability And Availability Without Compromising Performance

Authors: Aaron Ploetz ,Tejaswi Malepati ,Nishant Neeraj

3rd Edition

1789131499, 978-1789131499

More Books

Students also viewed these Databases questions

Question

What is the relation of physical mathematics with examples?

Answered: 1 week ago

Question

What are oxidation and reduction reactions? Explain with examples

Answered: 1 week ago