Check if it is possible to reach the point ( X , Y ) using distances given in an array | C ++ program for the above approach ; Function to check if the point ( X , Y ) is reachable from ( 0 , 0 ) or not ; Find the Euclidian Distance ; Calculate the maximum distance ; Case 1. ; Case 2. ; Otherwise , check for the polygon condition for each side ; Otherwise , print Yes ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int isPossibleToReach ( int A [ ] , int N , int X , int Y ) { double distance = sqrt ( double ( X * X + Y * Y ) ) ; double mx = 0 ; for ( int i = 0 ; i < N ; i ++ ) { mx += double ( A [ i ] ) ; } if ( mx < distance ) { cout << " NO " ; return 0 ; } if ( ( mx - distance ) < 0.000001 ) { cout << " YES " ; return 0 ; } for ( int i = 0 ; i < N ; i ++ ) { if ( distance + mx < double ( 2 ) * double ( A [ i ] ) ) { cout << " No " ; return 0 ; } } cout << " Yes " ; return 0 ; } int main ( ) { int A [ ] = { 2 , 5 } ; int X = 5 , Y = 4 ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; isPossibleToReach ( A , N , X , Y ) ; return 0 ; }