Pages

Wednesday, September 16, 2015

Counting Pixels (CPROM UiTM Arau 2015)

Consider printing an MxN rectangular grid of square boxes where each box has height and width of B pixel. Each black dot on the printed grid represents a single pixel. Your task is to compute the total of black dots to be used in printing the grid. The following example shows the calculation of the pixels:

Let B = 5, M=2, and N = 3. In this sampel, the total pixels is 63

Input
The first line of the input contains an integer T (1 ≤ T ≤ 5), the number of test cases. Following the first line are the test cases. Each line of a test case contains a single positive integer representing the size of each square box (B), the number of rows (M) and the number of columns (N), in the grid.
The input must be read from standard input.

Output
The output of the program should display a single integer representing the total number of pixels used to print the grid.

Samples Input
3
5 1 2
4 3 3
4 4 3

Samples Output
27
64
82


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Solved By Afiq
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.*;

public class Q6{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      String line =System.getProperty("line.separator");
      scan.useDelimiter(line);      
      int cases = scan.nextInt();
            
      for(int x=0;x<cases;x++){
         String [] get = scan.next().split(" ");
         
         int B = Integer.parseInt(get[0]);
         int M = Integer.parseInt(get[1]);
         int N = Integer.parseInt(get[2]);
         
         System.out.println(((B-2)*M*(N+1))+((M+1)*((B*N)-(N-1))));       
      }

   }
}

No comments:

Post a Comment