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.
- Program to find whether a no is power of two
- Write an Efficient Method to Check if a Number is Multiple of 3
- Program to find parity
- Find minimum number to be divided to make a number a perfect square
- Find whether a given number is a power of 4 or not
- Find Union and Intersection of two unsorted arrays
- Check if a number is multiple of 5 without using / and % operators
- To find sum of two numbers without using any operator
- Find day of the week for a given date
- Generate integer from 1 to 7 with equal probability
- Given a number, find the next smallest palindrome
- Find the element that appears once
- Find the largest multiple of 2, 3 and 5
- Program to find amount of water in a given glass
- How to check if two given line segments intersect?
- Find the maximum distance covered using n bikes
- Find if two rectangles overlap
- Find the smallest number whose digits multiply to a given number n
- Find next greater number with same set of digits
- Count ways to reach the n'th stair
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.