Found 7197 Articles for C++

C++ program to find largest or equal number of A whose sum of digits is divisible by 4

Arnab Chakraborty
Updated on 03-Mar-2022 05:39:41

182 Views

Suppose we have a number A. We have to find nearest larger or equal interesting number for A. A number is said to be interesting number if its sum of digits is divisible by 4. So, if the input is like A = 432, then the output will be 435, because 4 + 3 + 5 = 12 which is divisible by 4.StepsTo solve this, we will follow these steps −while (A / 1000 + A mod 1000 / 100 + A mod 100 / 10 + A mod 10) mod 4 is not equal to 0, do:    (increase A ... Read More

C++ program to find minimum number of locations to place bombs to kill all monsters

Arnab Chakraborty
Updated on 02-Mar-2022 12:26:48

316 Views

Suppose we have two arrays X and H. Both are with N elements, also have another two numbers D and A. Consider in a story, a silver fox is fighting with N monsters. The monsters are standing in a row, coordinate of ith monster is X[i], and its health is H[i]. Silver fox can use bombs to attack monsters. Dropping bomb at location x will damage all monsters within the range of x - D to x + D. Their health will be reduced by A. When all monsters have 0 health left, then the fox wins. We have to ... Read More

C++ program to count maximum possible division can be made in a graph with given condition

Arnab Chakraborty
Updated on 02-Mar-2022 12:21:17

165 Views

Suppose we have an adjacency matrix of a graph G. We have to check whether we can divide the vertices into non-empty sets V1, ... Vk, such that: every edge connects two vertices belonging to two adjacent sets. If the answer is yes, we have to find the maximum possible value of sets k, in such division.So, if the input is like010110101001010100101000100000010000then the output will be 4StepsTo solve this, we will follow these steps −Define an array dp of size: 210. n := size of matrix fl := 1 ans := 0 for initialize i := 0, when i < ... Read More

C++ program to find at least how much score it needs to get G amount of score

Arnab Chakraborty
Updated on 02-Mar-2022 12:24:07

305 Views

Suppose we have two arrays p and c both are with D number of elements each, and another number G. Consider in a coding contest, each problem has its score based on difficulty. The problem p[i] has score 100i. These p[1] + ... + p[D] problems are all of the problems present in the contest. a user in the coding site has a number total_score. The total_score of an user is the sum of the following two elements.Base score: the sum of score of all solved problemsBonus: when a user solves all problems with a score of 100i, he or ... Read More

C++ Program to find maximum possible smallest time gap between two pair of clock readings

Arnab Chakraborty
Updated on 02-Mar-2022 11:27:24

189 Views

Suppose we have an array D with N elements. Consider in a code festival there are N+1 participants including Amal. Amal checked and found that the time gap between the local times in his city and the i-th person's city was D[i] hours. The time gap between two cities: For any two cities A and B, if the local time in city B is d o'clock at the moment when the local time in city A is 0 o'clock, then the time gap between these two cities is minimum of d and 24−d hours.Here, we are using 24-hour notation. Then, ... Read More

C++ Program to find pairs of sequences where sequence holds minimum and maximum elements

Arnab Chakraborty
Updated on 02-Mar-2022 11:23:37

361 Views

Suppose we have three numbers N, M and K. There are N horizontal rows and M vertical rows. We shall write an integer in between 1 and K on each cell, and define sequences A and B, such that −for each i in range 1 to N, A[i] is minimum of all elements in ith rowfor each j in range 1 to M, B[j] is maximum of all elements in jth columnWe have to find the number of pairs (A, B). If the answer is too large, return result mod 998244353.So, if the input is like N = 2; M ... Read More

C++ Program to find out if a palindromic matrix can be made from a given matrix

Arnab Chakraborty
Updated on 02-Mar-2022 11:18:46

398 Views

Suppose, we are given a matrix with dimensions h x w. The matrix contains English letters. We have to create another matrix that will contain palindromic rows and columns, i.e. each row and column would be palindromes. To do that, any arrangement of rows and columns can be done from the given matrix; but no element can be changed, i.e. an 'a' cannot be changed to a 'b'. If that is possible to make a palindromic matrix from the given matrix, we return true; or otherwise, we return false.So, if the input is like h = 4, w = 4, ... Read More

C++ Program to find out number of employees of different skill level to be transferred

Arnab Chakraborty
Updated on 02-Mar-2022 11:13:44

258 Views

Suppose, there are n employees in a company. Each of the employees is given a rank based on their skills. The ranks are numbered from 1 to k. The number of employees having a rank i is given in the array skill, where skill[i] represents the number of employees having rank i. Now, a new branch of the company has opened and employees of different skills have to be transported to that branch. The number of employees to be sent to that branch is m. We have to find a way so that we can transfer m employees of different ... Read More

C++ Program to find out the minimum difference value in n integer pairs

Arnab Chakraborty
Updated on 02-Mar-2022 11:09:42

261 Views

Suppose, we are given two arrays a and b that have a total of n and m values in them respectively. We have to make n or m number of pairs (whichever is minimum) using values from the two arrays. A pair must contain a value from array a and another one from array b. We have to make the pairs in such a way so that the difference of the value in the pairs is minimum and the same. We print the value as output.So, if the input is like n = 4, m = 4, a = {2, ... Read More

C++ Program to find out the sum of shortest cost paths for all given triplets

Arnab Chakraborty
Updated on 02-Mar-2022 11:05:16

313 Views

Suppose, there are n cities and m roads between the cities. The m roads are given to us in an array of roads where the roads are in the format {aource, destination, weight}. Now, we define a triplet (s, t, k) where s, t, and k are cities. Now we have to calculate the minimum time needed to get from city s to city t. To visit t from s, only cities within 1 to k can be visited. If city t is unreachable from s, then we return 0. We have to calculate the minimum time for all triplets ... Read More

Advertisements