Given four integers W, H, x and y. The task is to find if there exists multiple ways to draw a line through (x, y) to cut the rectangle into two equal parts. If there are multiple ways print Yes otherwise print No. The co-ordinates of rectangle are (0, 0), (W, 0), (W, H) and (0, H).
Note: The point (x, y) always lies inside or above the rectangle.
Input: W = 2, H = 2, x = 1, y = 1
Line segment joining the points (0, 0) and (2, 2)
or (0, 2) and (2, 0) etc. are all valid ways.
Input: W = 1, H = 3, x = 1, y = 2
Approach: The rectangle can be divided into two equal parts when the line is is drawn vertically, horizontally or diagonally through the centre of the rectangle. So, the answer will be Yes only if the point (x, y) is the centre of the rectangle i.e. (W / 2, H / 2) otherwise the answer will be No.
Below is the implementation of the above approach:
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.
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Minimum squares to evenly cut a rectangle
- Find two vertices of an isosceles triangle in which there is rectangle with opposite corners (0, 0) and (X, Y)
- Count number of triangles cut by the given horizontal and vertical line segments
- Ratio of area of a rectangle with the rectangle inscribed in it
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Number of ways to cut a stick of length N into in even length at most K units long pieces
- Find X and Y intercepts of a line passing through the given points
- Check if there exists a prime number which gives Y after being repeatedly subtracted from X
- Check if there exists a number with X factors out of which exactly K are prime
- Determine the number of squares of unit area that a given line will pass through.
- Maximum number of line intersections formed through intersection of N planes
- Number of ways N can be divided into four parts to construct a rectangle
- Count different numbers that can be generated such that there digits sum is equal to 'n'
- Count number of binary strings such that there is no substring of length greater than or equal to 3 with all 1's
- Slope of the line parallel to the line with the given slope
- Paper Cut into Minimum Number of Squares
- Maximum of smallest possible area that can get with exactly k cut of given rectangular
- Puzzle | Cut Blue Painted Cube
- Maximum given sized rectangles that can be cut out of a sheet of paper
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.