Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Problem Given your location, and the location of each smoothie store, sort the list by distance from you from shortest to longest, breaking ties
The Problem
Given your location, and the location of each smoothie store, sort the list by distance from you from shortest
to longest, breaking ties by xcoordinate lower comes first and then breaking 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 smoothie shop or not. If so determine that shop's ranking on the sorted list in distance from
you.
The Input to be read from standard input. Using file io on any submission either latest or history of
submissions while grading will result in zero in this assignment and in another past assignment
The first line of the input contains integers separated by spaces. The first two of these values are x and y x
y representing your location. The third integer is n n representing the number of smoothie
shops. The fourth integer is s s x representing the number of points to search for. The last integer,
t t 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 shops. 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
Then the next s lines of the input contain x and y coordinate values for searching. Both values on each line
will be integers with an absolute value less than or equal to
The Output to be printed to standard console output
The first n lines of output should contain the coordinates of the smoothie shops, sorted as previously mentioned.
These lines should have the xcoordinate, followed by a space, followed by the ycoordinate.
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 smoothie shop, output a line with the following
format:
x y found at rank R
where x y is the query point, and R is the onebased rank of that smoothie shop in the sorted list. Thus R
will be more than the array index in which x y is located, after sorting.
If the point queried does NOT contain a smoothie shop, output a line with the following format:
x y not found
Sample Input data Note: Query points in blue for
clarity.
Sample Output
not found
found at rank
found at rank
found at rank
not found
Additional Requirement:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started