We are provided with a 2D plane and a point (, ). We have to find a rectangle (, , , ) such that itencompasses the given point (, ). The rectangle chosen must satisfy the given condition . Ifmultiple rectangles are possible the we must choose the one with the least Euclid distance between the center of the rectangle and the point (, ).
Image Source – codeforces
Input : 70 10 20 5 5 3 Output :12 0 27 9 Input :100 100 32 63 2 41 Output :30 18 34 100
The logic behind the problem is as follows. First of all we reduce to lowest irreducible form by dividing a and b by . We think of the problem in two separate dimensions and independently. We find out the after dividing a and b by their gcd to find the maximum distance that we can cover safely by staying in the range of . Since we have to find rectangle with minimum distance of its center from the point (, ), therefore we start with the assumption that point (, ) is our center. Then we find and by subtracting and adding half of length to . If either or goes out of range then we shift the coordinates accordingly to bring it inside the range . Similarly we proceed to calculate and .
For the first example according to above logic the answer comes out to be .
12 0 27 9
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Ratio of area of a rectangle with the rectangle inscribed in it
- Check whether a given point lies inside a rectangle or not
- Check whether a given point lies on or inside the rectangle | Set 3
- Area of the largest Rectangle without a given point
- Check if any point overlaps the given Circle and Rectangle
- Check if a point lies on or inside a rectangle | Set-2
- Rotation of a point about another point in C++
- Reflection of a point at 180 degree rotation of another point
- Area of a largest square fit in a right angle triangle
- Length of longest rod that can fit into a cuboid
- How to auto-resize an image to fit a div container using CSS?
- CSS | fit-content() Property
- Find side of Square which makes minimal area to fit two identical rectangles inside it
- Represent a given set of points by the best possible straight line
- Coordinates of rectangle with given points lie inside
- Find minimum area of rectangle with given set of coordinates
- Possible number of Rectangle and Squares with the given set of elements
- Intersecting rectangle when bottom-left and top-right corners of two rectangles are given
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.