- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ code to find the lamps needed to light up a floor

Suppose, there is a floor divided into a grid that has n rows and m columns. Now the floor has to be lit using lamps. A lamp, if placed at the border of two cells can light up two cells. If the lamp is placed in the vertical border, it lights up the cells to its left and right and if it is placed in the horizontal border, it lights up cells to its front and back. Given n and m, we have to find out the minimum number of lamps needed to light up the whole floor.

So, if the input is like n = 5, m = 3, then the output will be 8.

## Steps

To solve this, we will follow these steps −

res := (n * m + 1) / 2 return res

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; #define N 100 int solve(int n, int m) { int res = (n * m + 1) / 2; return res; } int main() { int n = 5, m = 3; cout<< solve(n, m); return 0; }

## Input

5, 3

## Output

8

- Related Questions & Answers
- C++ code to find the number of scans needed to find an object
- C++ code to find minimum time needed to do all tasks
- Program to find minimum radius to light up all houses on a street in Python
- C++ program to find sum of all cells lighten by the lamps
- C++ code to find a point that satisfies the constraints
- Methods to Calculate the Illumination of Light
- Program to find number of coins needed to make the changes in Python
- Python program to find runner-up score
- Program to find out the minimum rotations needed to maximize the profit from a Ferris wheel in Python
- Program to find minimum jump needed to return from a folder to home in Python
- C++ code to find the number of dial rotations to print a string
- Add a light grey background color to the Bootstrap 4 card
- C++ code to find total elements in a matrix
- C++ program to find out the number of iterations needed to convert all cells to black
- How to Find out the source code of a transaction in SAP?

Advertisements