Found 33676 Articles for Programming

C++ program to check whether we can distribute bags so that two friends will get same amount of candies

Arnab Chakraborty
Updated on 03-Mar-2022 07:01:58

231 Views

Suppose we have an array A with 4 elements. There are 4 bags of candies, ith bag contains A[i] amount of candies. We want to give each bags to one of our two friends. We have to check whether we can distribute these bags in such a way that each friend receives the same amount of candies in total?So, if the input is like A = [1, 7, 11, 5], then the output will be True, because we can give the first and the third bag to the first friend, and the second and the fourth bag to the second ... Read More

C++ program to count in how many ways we can paint blocks with two conditions

Arnab Chakraborty
Updated on 03-Mar-2022 07:00:15

354 Views

Suppose we have three numbers N, M and K. Consider there are N blocks they are arranged in a row. We consider following two ways to paint them. The paints of two blocks different if and only if the blocks are painted in different colors in following two ways −For each block, use one of the M colors to paint it. (it is not mandatory to use all colors)There may be at most K pairs of adjacent blocks that are painted in the same color.If the answer is too large, return result mod 998244353.So, if the input is like N ... Read More

C++ program to find two points from two lines who are not same

Arnab Chakraborty
Updated on 03-Mar-2022 06:58:04

376 Views

Suppose we have two ranges (l1, r1), (l2, r2) represents two lines on x-axis. l1 < r1 and l2 < r2. These segments may intersect, overlap or coincide with each other. We have to find two numbers a and b, such that a is in range (l1, r1) and b is in (l2, r2) and a and b are distinct.So, if the input is like l1 = 2; r1 = 6; l2 = 3; r2 = 4, then the output will be a = 3, b = 4, other answers are also possible.StepsTo solve this, we will follow these steps ... Read More

C++ program to find number in given range where each digit is distinct

Arnab Chakraborty
Updated on 03-Mar-2022 06:55:49

515 Views

Suppose we have two numbers l and r. We have to find an integer x, which is in between l and r (both inclusive) and all digits in x are distinct.So, if the input is like l = 211; r = 230, then the output will be 213.StepsTo solve this, we will follow these steps −for initialize k := l, when k

C++ program to construct graph with certain conditions

Arnab Chakraborty
Updated on 03-Mar-2022 06:55:06

575 Views

Suppose we have two numbers N and K. Consider there is an undirected graph with N elements. N vertices satisfies the following conditions −The graph is simple and connectedVertices are numbered from 1 to NLet M be the number of edges in the graph. The edges are numbered from 1 to M. The length of the edge is 1. And Edge i connects vertex U[i] to vertex V[i].There are exactly K pairs of vertices (i, j) where i < j, such that the shortest distance between them is 2.If such graph exists, we have to construct that graph. Otherwise return ... Read More

C++ program to find winner of cell coloring game

Arnab Chakraborty
Updated on 03-Mar-2022 06:51:20

594 Views

Suppose we have two arrays A and B both are with N elements each. Consider Amal and Bimal are playing a game on a board whose cell numbers are numbered from 1 to N. And N-1 roads. Roads are connecting two cells. So ith road is connecting A[i] to B[i]. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. Initially the cell 1 is marked as black color, and cell N is white. Other cells are not colored. Amal plays first, and they are playing alternatively. Amal selects an uncolored cells that is ... Read More

C++ program to find nearest integer for which the number and its digits sum gcd is greater than 1

Arnab Chakraborty
Updated on 03-Mar-2022 06:52:03

226 Views

Suppose we have a number N. Consider a function gcdSum(x) of a positive integer x which is the gcd of that integer with its sum of digits. We have to find the smallest integer x >= n, such that gcdSum(x) > 1.So, if the input is like N = 31, then the output will be 33, because gcd of 31 and (3+1) is 1. The gcd of 32 and (3+2) is 1, and gcd of 33 and (3+3) is 3.StepsTo solve this, we will follow these steps −for initialize i := n, when i 0, do:       ... Read More

Differentiate a Laguerre series with multidimensional coefficients in Python

AmitDiwan
Updated on 03-Mar-2022 06:48:13

138 Views

To differentiate a Laguerre series, use the laguerre.lagder() method in Python. The method returns the Laguerre series coefficients c differentiated m times along axis. At each iteration the result is multiplied by scl. The argument c is an array of coefficients from low to high degree along each axis, e.g., [1, 2, 3] represents the series 1*L_0 + 2*L_1 + 3*L_2 while [[1, 2], [1, 2]] represents 1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) + 2*L_0(x)*L_1(y) + 2*L_1(x)*L_1(y) if axis=0 is x and axis=1 is y.The 1st parameter, c is an array of Laguerre series coefficients. If c is multidimensional the different axis correspond ... Read More

C++ program to find in how many bases we can represent the number not greater than M

Arnab Chakraborty
Updated on 03-Mar-2022 06:48:09

180 Views

Suppose we have a numeric string S, and another number M. Let d be the greatest digit in S. We have to find in many different integers not greater than M can be found by choosing an integer n not less than d+1 and seeing S as a base-n number?So, if the input is like S = "999"; M = 1500, then the output will be 3, because S as base 10 number, we get 999, as base 11 number, we get 1197, as base 12 number, we get 1413. These three values are the only ones that we can ... Read More

Differentiate a Laguerre series in Python

AmitDiwan
Updated on 03-Mar-2022 06:46:08

139 Views

To differentiate a Laguerre series, use the laguerre.lagder() method in Python. The method returns the Laguerre series coefficients c differentiated m times along axis. At each iteration the result is multiplied by scl. The argument c is an array of coefficients from low to high degree along each axis, e.g., [1, 2, 3] represents the series 1*L_0 + 2*L_1 + 3*L_2 while [[1, 2], [1, 2]] represents 1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) + 2*L_0(x)*L_1(y) + 2*L_1(x)*L_1(y) if axis=0 is x and axis=1 is y.The 1st parameter, c is an array of Laguerre series coefficients. If c is multidimensional the different axis correspond ... Read More

Advertisements