Question: Objectives Give practice with sorting in C . Give practice with 2 pointer logic in C . Story Your program printed an incantation, and seemingly
Objectives
Give practice with sorting in C
Give practice with pointer logic in C
Story
Your program printed an incantation, and seemingly the wrong one, because one of your apprentices
performed the spell and the magic is still lingering. Luckily, the spell did not destroy the forest
and instead has miraculously made the magical motes slow down to the point where they are
measurable and seemingly sphere shaped. The state of the magic gave you an idea.
You had some students work on producing various magic containment devices. Each device
has a limited capacity, and can contain only one mote of magic. A magic containment device acts
as a box with dimensions, a height, length, and width. A magical mote can fit in the box as long
as the motes volume does not exceed the devices volume.
Based on your devices and magical motes, you want to know the least amount of magic that
cannot be contained by your devices.
Problem
Given a list of magical devices as their dimensions and a list of magical motes as their radii,
determine the least volume of magic that cannot be contained by the given magical devices.
Input Specification
Input begins with a line containing integers, M and D M D representing the
number of magical motes and the number of magic containment devices respectively.
The following line contains M integers representing the radius of a magical mote. Each radius
will be at most
The following D lines each contain integers representing the length, width, and height of a
magical device. Each dimension will be at most
To make the problem easier Its guaranteed that changing the radius by at most relatively
will not change the answer.
Output Specification
Your program should print the least volume of the uncontained motes. To make the problem
easier Your answer will be accepted if is off by at most relative to the correct answer.
Example Input Output
Below is are example of cases that your program will be tested against. The below cases are not
meant to be extensive. It is your responsibility. You should work on developing your own cases.
Input Output
Example Explanation
Sample Case
In the first case there are motes. The volumes for the motes are approximately the following
In the first case there are magic containment devices. The volumes for the devices are
We can put the rd mote in the st device and the st mote in the rd device. None of the
remaining motes can fix in any of the devices. The sum of the volumes of the uncontained motes
is
Sample Case
Both motes can be contained.
Hints
Use types with floating points preferably double
Compute the volume of each device and mote
Store the volume in arrays one for devices and one for motes
Geometry
Volume of a box device is h l w
Volume of a sphere magical mote is
r
Sort the arrays by volume.
Always try to contain the largest mote not contained currently. If there is no device that
contain it move to the next one.
Track an index in the array of motes AND an index in the array of devices. Start with the
largest device first.
When a mote can be contained, move both indices.
When a mote cannot be contained, move only one of the indices.
Track sum of uncontained mote volume in some variable.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
