Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Problem Scenario: Monster City Tour You are in a monster city to capture monsters. It is of most importance for you to be aware of the locations of the nearby monsters. Keeping track of this...

1 answer below »
Problem Scenario: Monster City Tour

You are in a monster city to capture monsters. It is of most importance for you to be aware of the locations of
the nea
y monsters. Keeping track of this information is known as "monster tracing." You need to write a
small program for monster tracing to show your coding skills!

The monster city can be modeled on the Cartesian plane. You are located at the point (x, y). In addition, you
have the Cartesian coordinates of all monsters around you in the city. What you would like to do is write a
program that sorts these locations based on their distance from you, followed by handling queries. The queries
are of the form of a point you are thinking of visiting. Your program should identify if there is amonster at that
location, and if so, what their rank is on the sorted list of the monsters. If no monster is at that location, you
should co
ectly identify this.

Note: There are many important implementation restrictions for this assignment, so to make sure
everyone reads these, the section on implementation restrictions will be next, changing the order of the
sections as compared to other assignments.

Implementation Restrictions
1. You must use a specified combination of Merge Sort and Insertion Sort to sort the point data. Specifically,
for each input case, a threshold value, t, will be given. If the subsection of the a
ay to sort has t or fewer
values to sort, Insertion Sort should be used (The reason and this strategy was/will be
iefly discussed in
the class). Otherwise, Merge Sort should be used. Further details about the comparison used for the sorting
are below.
2. You must store your coordinates in a struct that contains two integer fields. You can add more fields if
needed.
3. You must implement a ReadData() function that reads the required inputs and return the points to be sorted.
(note that it deos not read the search queries)
4. You must write a function compareTo which takes in two pointers, ptrPt1 and ptrPt2, to coordinate
structs and returns a negative integer if the point pointed to by ptrPt1 is closer to you than the point pointed
to by ptrPt2, 0 if the two locations pointed to by both are identical locations, and a positive integer if the
point pointed to by ptrPt1 is farther from you than the point pointed to by ptrPt2. Exceptions to this will be
when the two pointers are pointing to points that are the same distance from you, but are distinct points. In
these cases, if ptrPt1's x coordinate is lower than ptrPt2's x coordinate, a negative integer must be returned.
Alternatively, if ptrPt1's x coordinate is greater than ptrPt2's x coordinate a positive integer must be
eturned. Finally, if the x coordinate of both points is the same, if ptrPt1's y coordinate is lower than ptrPt2's
y coordinate, a negative integer must be returned. If ptrPt1's y coordinate is greater than ptrPt2's y
coordinate, a positive integer must be returned.

5. Since your location must be used for sorting, please make the variable that stores your x and y coordinates
global. Your program should have no other global variables.

6. A Binary Search function must be used when answering queries.

7. Your sort function should take in the a
ay to be sorted, the length of the a
ay as well as the threshold
value, t, previously mentioned. This function should NOT be recursive. It should be a wrapper function. It
means it will call necessary sorting function from here.

8. The recursive sort function (you can call this mergeSort) should take in the a
ay, a starting index into the
a
ay, an ending index into the a
ay and the threshold value t. In this function, either recursive calls should
e made OR a call to an insertion sort function should be made.


The Problem
Given your location, and the location of each monster, sort the list by distance from you from shortest to
longest,
eaking ties by x-coordinate (lower comes first), and then
eaking those ties by y coordinate (lower
comes first).

After sorting, answer several queries about points in the coordinate plane. Specifically, determine if a query
point contains a monster or not. If so, determine that monster's ranking on the sorted list in distance from you.


The Input (to be read from standard input using scanf(No file I/O. Using file I/0 will get 0 in the
assignment) - Your Program Will Be Later Tested on Multiple test cases
The first line of the input contains 5 integers separated by spaces. The first integer is n (2 ≤ n ≤ 106), representing
the number of monsters. The second integer is s (1 ≤ s ≤ 2x105), representing the number of points to search
for. The third and fourth values are x and y (|x|, |y| ≤ 10000), representing your location. The last integer, t (1
≤ t ≤ 30), represents the threshold to be used for determining whether you run Merge Sort of Insertion Sort.

The next n lines of the input contain x and y coordinate values, respectively, separated by spaces, representing
the locations of monsters. Each of these values will be integers and the points will be distinct (and also different
from your location) and the absolute value of x and y for all of these coordinates will not exceed 10,000.

Then the next s lines of the file contain x and y coordinate values for searching. Both values on each line will
e integers with an absolute value less than or equal to 10,000.


The Output (to be printed to console as well as to out.txt file (it means you hav to use both printf and
fprintf. You can declare the output file pointer as a global variable as well)
The first n lines of output should contain the coordinates of the monsters, sorted as previously mentioned.
These lines should have the x-coordinate, followed by a space, followed by the y-coordinate.

The last s lines of output will contain the answers to each of the s queries in the input. The answer for a single
query will be on a line by itself. If the point queried contains a monster, output a line with the following format:

x y found at position R

where (x, y) is the query point, and R is the one-based rank or position of that monster in the sorted list. (Thus,
R will be 1 more than the a
ay index in which (x, y) is located, after sorting.)

If the point queried does NOT contain a monster, output a line with the following format:

x y not found








Sample Input data(Note: Query points in blue for clarity.)
XXXXXXXXXX
3 1
-6 -2
-4 3
4 -4
2 4
-1 3
2 2
0 -5
-4 -2
-6 6
4 4
-2 4
0 5
-4 6
2 -1
3 1
0 -5
0 5
-6 7

Sample Output (out.txt as well as in standard console output)
2 2
-1 3
3 1
-4 -2
-2 4
2 4
-4 3
0 -5
0 5
4 -4
4 4
-6 -2
-4 6
-6 6
2 -1 not found
3 1 found at position 3
0 -5 found at position 8
0 5 found at position 9
-6 7 not found

Additional Requirement:
You must have to read data from standard input using scanf and write the result to console and out.txt file.
You have to use Merge sort, insertion sort, and binary search for your solution based on the requirements
mentioned above. Without using them, you will get zero. The output must have to match with the sample
output format. Do not add additional space, extra characters or words with the output as we will use diff
command to check whether your result matches with our result. Next, you must have to write a well structure
Answered Same Day Mar 20, 2023

Solution

Nidhi answered on Mar 21 2023
27 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here