Menu Close

Minimum number of packages that Luke must drop…[Cprgm]FTC

Luke is trying to solve the puzzle problem during Mathematics class hour. He has a graph paper with G X N rows and columns, and the puzzle question is, an NCC training base in each cell for a total of G X N bases. He wants to drop food items to every point based on strategic points on the graph paper, marking each drop point with a red dot. If a base contains at least one food package inside or on top of its border fence, then it’s considered to be supplied. 

For example: if Luke has four bases in a 2×2 grid. If he drops a single food package where the walls of all four bases intersect, then those four cells can access the food package. 

Given G and N, what’s the minimum number of packages that Luke must drop to supply all of his bases?

Example :
G=2, N=3.

Food Packages can be dropped at the corner between cells (0, 0), (0, 1), (1, 0), (1, 1) , (0, 2) and (1, 2). This supplies all bases using packages.

Function Description:

  •  G: the number of rows
  •  N: the number of columns
Input:
Two space-separated integers describing the respective values of G and N.

Output:
The only line of output has single integer indicating the minimum number of food packages required

Explanation

Luke has four bases in a 2X2 grid. If he drops a single package where the walls of all four bases intersect, then those four cells can access the package:

Because he managed to supply all four bases with a single supply drop, we print 1 as our answer.

#include <stdio.h>
int NccCells(int x,int y)
{int package;
 package=((x+1)/2)*((y+1)/2);
 return package;
}
int main()
{int G,N;
  scanf("%d %d",&G,&N);
  int package;
  package=NccCells(G,N);
  printf("%d",package);
return 0;
}


INPUT_1:
2  2

OUTPUT:
1


INPUT_2:
1  4

OUTPUT:
2