Given a square of size n . There are n2 small squares inside the square n of size 1 unit each, in which any one of the square is colored. Our task is to cut the square n into two equal parts. The cutting line should not have any common points with the colored cell and the resulting two parts should be equal up to rotation. Print “YES” if it’s possible to cut the square with such conditions and “NO” otherwise.
Note : The value of n should always be an even positive number.
Input : n = 4, x = 1, y = 1 Output : YES // n = 4 and 1 1 is the coordinate of the colored square Input : n = 2, x = 1, y = 1 Output : NO
In the first example the painted square has a coordinate 1 x 1 . So we have to cut the bigger square into two parts so that there should not be any common point with the colored cell. The bold line shown in the above picture cuts the square into two equal parts.
Below is the step by step algorithm to solve this problem:
1 . Initialize the size of the square and the position of the painted square.
2 . Dividing a square into two equal parts will only be possible if the cutting line will pass through the center of our bigger square.
3 . Thus, if the painted square is linked anyway to the center of the bigger square then it is not possible to cut the bigger square into two equal parts.
4 . So to check, divide the size of bigger square into half and check if any dimension of a painted square is linked anyway to it.
Below is the implementation of above approach:
- Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts
- Number of ways N can be divided into four parts to construct a rectangle
- Check if a line at 45 degree can divide the plane into two equal weight parts
- Sum of all parts of a square Matrix divided by its diagonals
- Maximum of all distances to the nearest 1 cell from any 0 cell in a Binary matrix
- Divide N into K unique parts such that gcd of those parts is maximum
- Split a string in equal parts such that all parts are palindromes
- Find the sums for which an array can be divided into sub-arrays of equal sum
- Check if cells numbered 1 to K in a grid can be connected after removal of atmost one blocked cell
- Minimum cuts required to divide the Circle into equal parts
- Check if a cell can be visited more than once in a String
- Check if a Queen can attack a given cell on chessboard
- Check if a right-angled triangle can be formed by moving any one of the coordinates
- Check whether two strings can be made equal by reversing substring of equal length from both strings
- Querying the number of distinct colors in a subtree of a colored tree using BIT
- Find the minimum spanning tree with alternating colored edges
- Count of distinct colors in a subtree of a Colored Tree with given min frequency for Q queries
- Count of strings that become equal to one of the two strings after one removal
- Partition N into M parts such that difference between Max and Min part is smallest
- Find the number of ways to divide number into four parts such that a = c and b = d
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.