# Find if there exists multiple ways to draw line through (x, y) to cut rectangle in equal halfs

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.

**Examples:**

Input:W = 2, H = 2, x = 1, y = 1

Output:Yes

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

Output:No

**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:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function that returns true if multiple ` `// lines are possible passing through ` `// (x, y) that divide the given ` `// rectangle into two equal parts ` `int` `isPossible(` `int` `w, ` `int` `h, ` `int` `x, ` `int` `y) ` `{ ` ` ` ` ` `// If the point (x, y) is the ` ` ` `// centre of the rectangle ` ` ` `if` `(x * 2 == w && y * 2 == h) ` ` ` `return` `true` `; ` ` ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `w = 1, h = 2, x = 1, y = 2; ` ` ` ` ` `if` `(isPossible(w, h, x, y)) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` `// Function that returns true if multiple ` `// lines are possible passing through ` `// (x, y) that divide the given ` `// rectangle into two equal parts ` `static` `boolean` `isPossible(` `int` `w, ` `int` `h, ` `int` `x, ` `int` `y) ` `{ ` ` ` ` ` `// If the point (x, y) is the ` ` ` `// centre of the rectangle ` ` ` `if` `(x * ` `2` `== w && y * ` `2` `== h) ` ` ` `return` `true` `; ` ` ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `w = ` `1` `, h = ` `2` `, x = ` `1` `, y = ` `2` `; ` ` ` ` ` `if` `(isPossible(w, h, x, y)) ` ` ` `System.out.print(` `"Yes"` `); ` ` ` `else` ` ` `System.out.print(` `"No"` `); ` `} ` `} ` ` ` `// This code contributed by PrinciRaj1992 ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 implementation of the approach ` ` ` `# Function that returns true if multiple ` `# lines are possible passing through ` `# (x, y) that divide the given ` `# rectangle into two equal parts ` `def` `isPossible(w, h, x, y): ` ` ` ` ` `# If the point (x, y) is the ` ` ` `# centre of the rectangle ` ` ` `if` `(x ` `*` `2` `=` `=` `w ` `and` `y ` `*` `2` `=` `=` `h): ` ` ` `return` `True` ` ` ` ` `return` `False` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `'__main__'` `: ` ` ` `w ` `=` `1` ` ` `h ` `=` `2` ` ` `x ` `=` `1` ` ` `y ` `=` `2` ` ` ` ` `if` `(isPossible(w, h, x, y)): ` ` ` `print` `(` `"Yes"` `) ` ` ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# This code is contributed by Surendra_Gangwar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function that returns true if multiple ` `// lines are possible passing through ` `// (x, y) that divide the given ` `// rectangle into two equal parts ` `static` `bool` `isPossible(` `int` `w, ` `int` `h, ` ` ` `int` `x, ` `int` `y) ` `{ ` ` ` ` ` `// If the point (x, y) is the ` ` ` `// centre of the rectangle ` ` ` `if` `(x * 2 == w && y * 2 == h) ` ` ` `return` `true` `; ` ` ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main () ` `{ ` ` ` `int` `w = 1, h = 2, x = 1, y = 2; ` ` ` ` ` `if` `(isPossible(w, h, x, y)) ` ` ` `Console.Write(` `"Yes"` `); ` ` ` `else` ` ` `Console.Write(` `"No"` `); ` `} ` `} ` ` ` `// This code is contributed by ajit. ` |

*chevron_right*

*filter_none*

**Output:**

No

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

## Recommended Posts:

- Equation of straight line passing through a given point which bisects it into two equal line segments
- Number of ways N can be divided into four parts to construct a rectangle
- Check whether a subsequence exists with sum equal to k if arr[i]> 2*arr[i-1]
- Count ways to reach the Nth stair using multiple 1 or 2 steps and a single step 3
- Number of ways of choosing K equal substrings of any length for every query
- Ratio of area of a rectangle with the rectangle inscribed in it
- Find minimum area of rectangle with given set of coordinates
- Find the percentage change in the area of a Rectangle
- Program to find Perimeter / Circumference of Square and Rectangle
- Find the cordinates of the fourth vertex of a rectangle with given 3 vertices
- Find two vertices of an isosceles triangle in which there is rectangle with opposite corners (0, 0) and (X, Y)
- Find the multiple of x which is closest to a^b
- Find the largest multiple of 2, 3 and 5
- Find the largest possible k-multiple set
- Find First element in AP which is multiple of given prime

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.