Dipesh Financial Crisis - Daily Coding Problems

Dipesh Financial Crisis - Daily Coding Problems



1.     DIPESH’S FINANCIAL CRISIS
Dipesh is in financial crisis these days, so to pay his debt he has to sell his land. The dimensions of the land are given. He wants to sell this land by cutting into pieces of (1x1) units. But cutting a land has its own cost, each cut can be made either horizontally or vertically. Help find Dipesh the minimum cost incurred during cutting the land.

Input Format:
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Each test case contains two integers n and m denoting the length and breadth of land respectively. Next line contains an integer k denoting the cost of each cut on the land.
Output Format:
For each test case output the cost incurred to cut Dipesh's land in a Separate line.
Sample Input:  1
                              4 9
                              2
Sample Output:  22


SOLUTION:
Points to note:
·        Dipesh wants to cut his land into pieces of 1x1
·        One cut can be made at a single time either horizontally or vertically.
·        We need to take in the number of test case(number of times you want to execute your code on different set of inputs).
·        Each test case will have two input: firstly dimensions in single line so you need to split that and store in dimension variables. Secondly the cost of each cut.
·        We need to calculate the total number of cuts that Dipesh could make to minimize his cutting cost.
·        Finally output the cost for cutting the land into pieces.

Suppose the dimensions are 5x3 and cost of per single cut equals to 2. Then the minimum number of cuts could be: 
 Total Horizontal cuts = 3-1 = 2
Total Vertical cuts = 5-1 = 4
Total number of cuts = 2 + 4 = 6
Therefore cost is 6 x 2 = 12

Here goes the code:

Post a Comment

0 Comments