Given three 2-Dimentional vector co-ordinates A, B and C. The task is to perform below operations any number of times on vector A to get vector B :
- Rotate the vector 90 degrees clockwise.
- Add vector C to it.
Print “YES” B is obtained using the above operations, else Print “NO”.
Input: Vector A: 2 3, Vector B: 2 3, Vector C: 0 0 Output: YES The given vector A has coordinate (2, 3) and we need to convert this vector A to vector B which is also (2, 3). By rotating vector A 4 times by 90 degrees and adding it to vector C(0, 0) will give us vector B(2, 3). Input: Vector A: 0 0, Vector B: 1 1, Vector C: 2 2 Output: NO
Below is the step by step algorithm to solve this problem:
- Initialize three vectors of 2-D coordinates as A ( a, b ), B ( x, y ) and C ( p, q ).
- Coordinates of vector A can be of any quadrant. So, initialize a check function for all the quadrant and check if any of it is true.
- Find a-x and b-y, which will tell us how much we need to make it to vector B.
- Initialize d = p*p + q*q. If d = 0 then you need not to add anything in vector A.
- If D > 0, then check if a*p + b*q and b*p – a*q is in the multiple of ‘d’ so that it is possible to get the vector B.
Below is the implementation of above algorithm:
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.
- Check if it is possible to make array increasing or decreasing by rotating the array
- Minimize steps to reach K from 0 by adding 1 or doubling at each step
- Check if it is possible to reach a number by making jumps of two given length
- Check if it is possible to reach (x, y) from origin in exactly Z steps using only plus movements
- Check if it is possible to reach (X, Y) from (1, 0) by given steps
- Check if it is possible to reach (X, Y) from (1, 1) by given steps
- Maximum distance between two points in coordinate plane using Rotating Caliper's Method
- Queries to find maximum sum contiguous subarrays of given length in a rotating array
- Is it possible to reach N and M from 1 and 0 respectively as per given conditio
- Find minimum possible digit sum after adding a number d
- Find the winner by adding Pairwise difference of elements in the array until Possible
- Count of all possible ways to reach a target by a Knight
- Check whether the number can be made perfect square after adding 1
- Check whether N can be a Perfect Cube after adding or subtracting K
- Check whether the number can be made perfect square after adding K
- Check whether the number can be made palindromic after adding K
- Check if given intervals can be made non-overlapping by adding/subtracting some X
- Minimum LCM and GCD possible among all possible sub-arrays
- Reach A and B by multiplying them with K and K^2 at every step
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
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.