Luke is daydreaming in Math class. He has a sheet of graph paper with n rows and m columns, and he imagines that there is an army base in each cell for a total of n.m bases. He wants to drop supplies at strategic points on the sheet, marking each drop point with a red dot. If a base contains at least one package inside or on top of its border fence, then it's considered to be supplied.
Given n and m, what's the minimum number of packages that Luke must drop to supply all of his bases?
Example:
Input: n = 2, m = 2
Output: 1
Approach
C++
#include <bits/stdc++.h>using namespace std;int gameWithCells(int n, int m){return (n + n % 2) * (m + m % 2) / 4;}int main(){int n = 2, m = 2;cout << gameWithCells(n, m) << "\n";return 0;}
No comments:
Post a Comment