Found 7347 Articles for C++

Maximum number of pieces in N cuts in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:14:19

555 Views

Given the task is to calculate the maximum number of square or rectangle pieces of equal size that can be obtained by cutting a given square piece in total N number of cuts horizontally or vertically.Let’s now understand what we have to do using an example −Input − N=8Output − 25Explanation − When N=8, the number of vertical cuts = 4 and the number of horizontal cuts = 4.Total pieces = 2512345678910111213141516171819202122232425Input − 7Output − 201234567891011121314151617181920Approach used in the below program as followsIf N is the number of cuts and we have to maximize the resultant pieces then equal number ... Read More

Maximum number of parallelograms that can be made using the given length of line segments in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:12:37

88 Views

Given the task is to find the maximum number of parallelograms that can be made using given N number of line segments if each line segment can be used at most in one parallelogram.Let’s now understand what we have to do using an example −Input − Arr[] = {8, 3, 1, 3, 8, 7, 1, 3, 5, 3}Output − 2Explanation − With the above given line segments, the two parallelograms that can be formed are with sides 8, 1, 8, 1 and 3, 3, 3, 3 respectively.Input − Arr[] = {7, 9, 9, 7}Output − 1Approach used in the below ... Read More

Maximum number of ones in a N*N matrix with given constraints in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:10:45

80 Views

Given the task is to find the maximum number of ones in a binary matrix possible with the following constraints.Two integers N and X are given where X

Maximum number of groups of size 3 containing two type of items in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:09:27

132 Views

Given the task is to calculate the maximum number of groups of size 3 that can be formed when N number of items of type A and M number of items of type B are given.Also, each group should have at least one item of each type, that is either A or B.Let’s now understand what we have to do using an example −Input − N=3, M=5Input − 2ExplanationGroup 1: 1 item of type A and 2 items of type B Group 2: 1 item of type A and 2 items of type B In total, 2 items of type ... Read More

Maximum number of dots after throwing a dice N times in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:07:36

110 Views

Given the task is to calculate the maximum number of dots that can be expected after throwing a dice N times having M faces.The first face of the dice contains 1 dot, the second face has 2 dots and so on. Likewise the M-th face contains M number of dots.The probability of appearance of each face becomes 1/M.Let’s now understand what we have to do using an example −Input − M=2, N=3Output − 1.875Explanation − The dice has 2 sides = {1, 2}If the dice is thrown 3 times then the sample space will be = MN = 23{(1, 1, ... Read More

Sum of the series 2^0 + 2^1 + 2^2 +...+ 2^n in C++

sudhir sharma
Updated on 17-Aug-2020 09:17:02

820 Views

In this problem, we are given a number n which defines the n-th term of the series 2^0, 2^1, 2^2, …, 2^n. Our task is to create a program to find the sum of the series 2^0 + 2^1 + 2^2 +...+ 2^n.Let’s take an example to understand the problem, Inputn=6Output Explanation sum = 2^0 + 2^1 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 sum = 1 + 2 + 4 + 8 + 16 + 32 + 64 = 127A simple solution to the problem is by using the loop. Finding the 2^i, for each value from 0 ... Read More

Maximize number of continuous Automorphic numbers in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:05:49

228 Views

Given the task is to maximize the number of continuous Automorphic elements in a given array with N number of elements.An automorphic number is a number whose square ends with the same digits as the number itself. For example 5 is an automorphic number as 5*5 = 25 and 25 ends with 5.Let’s now understand what we have to do using an example −Input − arr[]={5, 3, 625, 6, 8, 1}Output − 2Explanation − Automorphic numbers present in the above array are 5, 625, 6 and 1 but the maximum continuous automorphic numbers are {625, 6} which makes the output ... Read More

Maximize the size of array by deleting exactly k sub-arrays to make array prime in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:03:00

78 Views

Given the task is to delete exactly K sub-arrays from a given array Arr[] with N positive elements such that all the remaining elements in the array are prime and the size of the remaining array is maximum.Input Arr[]={4, 3, 3, 4, 3, 4, 3} , K=2Output 3Explanation − K=2, this means only 2 sub-arrays must be deleted.The sub-arrays deleted are Arr[0] and Arr[3…5] which leaves the array Arr[]={3, 3, 3} with all the prime elements and the maximum size possible.Input Arr[]={7, 6, 2, 11, 8, 3, 12}, K=2Output 3Explanation − The sub-arrays deleted are Arr[1] and Arr[4…6] and the remaining prime array is ... Read More

Maximize the sum of products of the degrees between any two vertices of the tree in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:59:08

248 Views

Given the task is to construct a tree with a given integer N such that, the sum of degree(x) * degree(y) for all ordered pairs (x, y) is maximum and x is not equal to y.Input −N=5Output −50Explanation    1     \      2       \        3          \           4             \              5 Degree of 1st node = 1 Degree of 2nd node = 2 Degree of 3rd node = 2 Degree of 4th node ... Read More

Maximum length of subarray such that sum of the subarray is even in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:52:38

797 Views

We are given with an array Arr[] of integers. The goal is to find longest length subarray of Arr[] , sum of whose elements is even. That is, the sum of elements of a subarray is even and that subarray is longest in length.Input − Arr[] = { 2, 3, 5, 2, 6, 7 }.Output −Maximum length of subarray − 4Explanation −The maximum length subarray is { 5, 2, 6, 7 }. Sum is 20 which is even.Input − Arr[] = { 5, 7, 7, 3, 4 }.Output − Maximum length of subarray − 4Explanation − The maximum length subarray ... Read More

Advertisements