Found 26504 Articles for Server Side Programming

C++ program to find out the maximum sum of a minimally connected graph

Arnab Chakraborty
Updated on 25-Feb-2022 11:18:57

253 Views

Suppose, we are given a minimally connected graph. That means removing any edge will make the graph disconnected. The graph has n vertices and the edges are given in an array 'edges'. There is also an array 'vertexValues' given to us that contain n integer values.Now, we do the following −We write a positive integer on each of the vertices and then try to calculate a score.There is an edge connecting two vertices, we put the smaller value of the two vertices on the edges.We calculate the score by adding all the edge values.We have to find the maximum value ... Read More

C++ Program to find out the cost to travel all the given coordinates

Arnab Chakraborty
Updated on 25-Feb-2022 11:07:24

266 Views

Suppose, we are given n three-dimensional coordinates. The cost to travel from coordinate (a, b, c) to (x, y, z) is ∣ x − a∣ + ∣ y − b∣ + max(0, z − c). We start from the first coordinate, then visit all the coordinates at least once, and then return to the first coordinate. We have to find out the total cost of this whole trip. The coordinates are given to us in the array 'coords'.So, if the input is like n = 3, coords = {{1, 1, 0}, {1, 3, 4}, {3, 2, 2}}, then the output ... Read More

C++ Program to find out the number of jumps needed for a robot to reach a particular cell in a grid

Arnab Chakraborty
Updated on 25-Feb-2022 10:46:30

256 Views

Suppose, we have a grid of dimensions h x w. The grid is represented in a 2D array called ‘initGrid’, where each cell in the grid is either represented by a '#' or a '.'. '#' means that the grid contains an obstacle and '.' means that there is a path through that cell. Now, a robot is placed on a cell 'c' on the grid having row number x and column number y. The robot has to travel to another cell 'd' having row number p and column number q. Both the cell coordinates c and d are presented ... Read More

C++ Program to find out the number of unique matrices that can be generated by swapping rows and columns

Arnab Chakraborty
Updated on 25-Feb-2022 10:31:41

194 Views

Suppose, we have a n x n matrix. Each element in the matrix is unique and is an integer number between 1 and n2. Now we can perform the operations below in any amount and any order.We pick any two integers x and y that are in the matrix, where (1 ≤ x < y ≤ n) and swap the columns containing x and y.We pick any two integers x and y that are in the matrix, where (1 ≤ x < y ≤ n) and swap the rows containing x and y.We have to note that x + y ... Read More

C++ Program to find out the total cost required for a robot to make a trip in a grid

Arnab Chakraborty
Updated on 25-Feb-2022 10:05:21

198 Views

Suppose, we are given a grid of dimensions h x w. Each cell in the grid contains some positive integer number. Now there is a path-finding robot placed on a particular cell (p, q) (where p is the row number and q is the column number of a cell) and it can be moved to cell (i, j). A move operation has a particular cost, which is equal to |p - i| + |q - j|. Now there are q number of trips, which has the following properties.Each trip has two values (x, y) and there is a common value ... Read More

Multiply one polynomial to another in Python

AmitDiwan
Updated on 25-Feb-2022 08:25:14

2K+ Views

To multiply one polynomial to another, use the numpy.polynomial.polynomial.polymul() method in Python. Returns the multiplication of two polynomials c1 + c2. The arguments are sequences of coefficients from lowest order term to highest, i.e., [1, 2, 3] represents the polynomial 1 + 2*x + 3*x**2.The method returns the coefficient array representing their sum. The parameters c1 and c2 are the 1-D arrays of coefficients representing a polynomial, relative to the “standard” basis, and ordered from lowest order term to highest.This numpy.polynomial.polynomial module provides a number of objects useful for dealing with polynomials, including a Polynomial class that encapsulates the usual ... Read More

Subtract one polynomial to another in Python

AmitDiwan
Updated on 25-Feb-2022 08:22:44

436 Views

To subtract one polynomial to another, use the numpy.polynomial.polynomial.polysub() method in Python. Returns the difference of two polynomials c1 + c2. The arguments are sequences of coefficients from lowest order term to highest, i.e., [1, 2, 3] represents the polynomial 1 + 2*x + 3*x**2.The method returns the coefficient array representing their difference. The parameters c1 and c2 returns 1-D arrays of polynomial coefficients ordered from low to high.This numpy.polynomial.polynomial module provides a number of objects useful for dealing with polynomials, including a Polynomial class that encapsulates the usual arithmetic operations.StepsAt first, import the required libraries -from numpy.polynomial import polynomial ... Read More

Add one polynomial to another in Python

AmitDiwan
Updated on 25-Feb-2022 08:20:40

2K+ Views

To add one polynomial to another, use the numpy.polynomial.polynomial.polyadd() method in Python. Returns the sum of two polynomials c1 + c2. The arguments are sequences of coefficients from lowest order term to highest, i.e., [1, 2, 3] represents the polynomial 1 + 2*x + 3*x**2.The method returns the coefficient array representing their sum.The parameters c1 and c2 returns 1-D arrays of polynomial coefficients ordered from low to high.This numpy.polynomial.polynomial module provides a number of objects useful for dealing with polynomials, including a Polynomial class that encapsulates the usual arithmetic operations.StepsAt first, import the required libraries-from numpy.polynomial import polynomial as PDeclare ... Read More

Get the inverse of a 3D array in Python

AmitDiwan
Updated on 25-Feb-2022 08:17:39

750 Views

To compute the inverse of a 3D array, use the numpy.linalg.tensorinv() method in Python. The result is an inverse for a relative to the tensordot operation tensordot(a, b, ind), i. e., up to floating-point accuracy, tensordot(tensorinv(a), a, ind) is the “identity” tensor for the tensordot operation. The method returns a’s tensordot inverse, shape a.shape[ind:] + a.shape[:ind].The 1st parameter is a, the Tensor to ‘invert’. Its shape must be ‘square’, i. e., prod(a.shape[:ind]) == prod(a.shape[ind:]). The 2nd parameter is ind, the number of first indices that are involved in the inverse sum. Must be a positive integer, default is 2.StepsAt first, ... Read More

Get the inverse of a Four-Dimensional array in Python

AmitDiwan
Updated on 25-Feb-2022 07:54:35

472 Views

To compute the inverse of a Four-Dimensional array, use the numpy.linalg.tensorinv() method in Python. The result is an inverse for a relative to the tensordot operation tensordot(a, b, ind), i. e., up to floating-point accuracy, tensordot(tensorinv(a), a, ind) is the “identity” tensor for the tensordot operation.The method returns a’s tensordot inverse, shape a.shape[ind:] + a.shape[:ind]. The 1st parameter is a, the Tensor to ‘invert’. Its shape must be ‘square’, i. e., prod(a.shape[:ind]) == prod(a.shape[ind:]). The 2nd parameter is ind, the number of first indices that are involved in the inverse sum. Must be a positive integer, default is 2.StepsAt first, ... Read More

Advertisements