Sunday, 28 November 2021

Park Lighting Problem !!!

 PROBLEM 23: Park Lighting


Problem Reference : Codeforces 

Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.

The park is a rectangular table with n rows and m columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length 1. For example, park with n=m=2 has 12 streets.

You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).

Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.


Input:

The first line contains a single integer t (1t104) — the number of test cases in the input. Then t test cases follow.

Each test case is a line containing two integers nm (1n,m104) — park sizes.


Output:

Print t answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.


Solution: 


  1. import math
  2. t = int(input())
  3. i = 0
  4. while i < t:
  5. i += 1
  6. n1,m1 = input().split()
  7. n = int(n1)
  8. m = int(m1)
  9. o = (n*m) / 2
  10. print(math.ceil(o))


The above solution is in python language.



Example
input
5
1 1
1 3
2 2
3 3
5 3
output
1
2
2
5
8

No comments:

Post a Comment

Rearrange an array with O(1) extra space

  PROBLEM 61:  Rearrange an array with O(1) extra space (For best view experience, view in windows version) Problem Reference : GeeksForGeek...