Server Side Programming Articles - Page 569 of 2650

C++ program to find minimum possible difference of largest and smallest of crackers

Arnab Chakraborty
Updated on 03-Mar-2022 07:13:47

335 Views

Suppose we have two numbers N and K. We want to distribute N crackers to K users. We have to find the minimum possible difference between the largest number of crackers received by a user and smallest number received by a user.So, if the input is like N = 7; K = 3, then the output will be 1, because when the users receive two, two and three crackers, respectively, the difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.StepsTo solve this, we will follow these steps −if ... Read More

Python – numpy.logspace

Syed Abeed
Updated on 03-Mar-2022 07:11:59

410 Views

numpy.logspace returns a set of numbers spaced evenly on a log scale. Its syntax is as follows −numpy.logspace(start, stop, num = 50, endpoint = True/False, base = 10.0, dtype = None)ParametersThe logspace function can accept the following parameters −start − Start of the sequence; default is zero.stop − Endpoint of the sequence.num − Number of elements to be generated between the start and stop sequence.endpoint − It controls whether the stop value is included in the output array or not. If the endpoint is True, then the stop parameter is included as the last item in the nd.array. If endpoint=false, ... Read More

C++ program to check the coins forms x amount of rupees or not

Arnab Chakraborty
Updated on 03-Mar-2022 07:11:53

165 Views

Suppose we have two numbers K and X. Consider Amal has K, 500 rupee notes. We have to check whether the sums up to X rupees or not.So, if the input is like K = 2; X = 900, then the output will be True, because 2*500 = 1000 and it is not less than 900.StepsTo solve this, we will follow these steps −if (500 * k) >= x, then:    return true Otherwise    return falseExampleLet us see the following implementation to get better understanding −#include using namespace std; bool solve(int k, int x){    if ((500 * k) >= x){       return true;    } else{       return false;    } } int main(){    int K = 2;    int X = 900;    cout

Python – numpy.linspace

Syed Abeed
Updated on 03-Mar-2022 07:05:40

2K+ Views

The numpy.linspace function is used to create a set of evenly spaced numbers within a defined interval.Syntaxnumpy.linspace(start, stop, num = 50, endpoint = True/False, retstep = False/True, dtype = None)ParametersThe function can accept the following parameters −start − Start of the sequence; by default, it is considered as zero.stop − Endpoint of the sequence.num − Number of elements to be generated between start and stop.endpoint − It controls whether the stop value is included in the output array or not. If the endpoint is True, then the stop parameter is included as the the last item in the nd.array. If ... Read More

C++ program to count in how many ways we can minimize cable length to connect computers

Arnab Chakraborty
Updated on 03-Mar-2022 07:02:43

311 Views

Suppose we have two arrays A and B both with N elements. Consider there are N computers and N sockets. The coordinate of ith computer is A[i] and coordinate of ith socket is b[i]. These 2N coordinates are pair-wise distinct. We want to connect each computer with a socket by cables. Each socket can be connected at most one computer. We have to count in how many ways we can minimize the length of cables. If the answer is too large, return result mod 10^9 + 7.So, if the input is like A = [0, 10]; B = [20, 30], ... Read More

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

242 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

365 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

383 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

519 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

582 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

Advertisements