Monday, 29 Nov 2021
Category: Geometric-Lines

Given N horizontal lines represented by an array position[][] of size N, where position[i] represents the ith horizontal line which has x-coordinates from position[i] to position[i] and an integer K, which represents the maximum number of vertical lines that can be drawn, the task is to check if N given lines can be intersected by […]

Given a 2D array arr[][], representing width of bricks of the same height present on a wall, the task is to find the minimum number of bricks that can be intersected by drawing a straight line from the top to the bottom of the wall.Note: A line is said to intersect a brick if it […]

#include using namespace std;  void check_position(int a, int b, int c, int d,                    int x1, int y1, int z1,                    int x2, int y2, int z2){        int value_1 = a * x1 + b * y1 + c * z1 + d;    int value_2 = a * x2 + b * y2 + c * z2 + d;          if ((value_1 > 0 […]

#include using namespace std;  double radius(int a, int b, int c){            int g = a / 2;    int f = b / 2;          if (g * g + f * f – c < 0)        return (-1);          return (sqrt(g * g + f * f - c));}  double centerDistanceFromLine(int a, int b,                              int i, int j,                              int k){        int g = a / 2;    int f […]

Check if two circles intersect such that the third circle passes through their points of intersections and centersGiven centres and the radii of three circles A, B, and C in the form of {X, Y, R}, where (X, Y) is the centre of the circle and R is the radius of that circle. The task […]

Given four positive integers A, B, C, and D representing the length of sides of a Cyclic Quadrilateral, the task is to find the area of the Cyclic Quadrilateral.Examples:Input: A = 10, B = 15, C = 20, D = 25Output: 273.861Input: A = 10, B = 30, C = 50, D = 20Output: 443.706Approach: […]

Size of smallest square that contains N non-overlapping rectangles of given dimensions Given two positive integers W and H and N rectangles of dimension W*H, the task is to find the smallest size of the square required such that all the N rectangles can be packed without overlapping. Examples:Input: N = 10, W = 2, H […]

#include using namespace std;  void crossProduct(int vect_A[],                  int vect_B[],                  int cross_P[]){        cross_P        = vect_A * vect_B          – vect_A * vect_B;          cross_P        = vect_A * vect_B          – vect_A * vect_B;          cross_P        = vect_A * vect_B          – vect_A * vect_B;}  void checkCollinearity(int x1, int y1,                       int z1, int x2,                       int y2, int z2){        int A = { x1, y1, z1 };    int B = { x2, y2, z2 };          int cross_P;          crossProduct(A, B, cross_P);              if (cross_P == […]

#include using namespace std;  void finalPosition(char a[], int b[],                   int M){                int n = 0, s = 0, e = 0, w = 0;              char p = ‘N’;          for (int i = 0; i < M; i++) {                          if (p == 'N') {              if (a[i] == 'U') {                p = 'N';                n = n + b[i];            }            else if (a[i] == 'D') {                p = 'S';                s = […]

Given two arrays X[] and Y[], representing points on X and Y number lines, such that every similar-indexed array element forms a line segment, i.e. X[i] and Y[i] forms a line segment, the task is to find the maximum number of line segments that can be selected from the given array. Examples: Input: X[] = […]