Codeforces Beta Round #1 A. Theatre Square 题解

Title link: http: //codeforces.com/contest/1/problem/A
Title effect:
to a rectangular n × m ground you, you use a × a ground tile covered it. But you can not destroy these tiles,
and tile shop you must be long or wide and parallel to the ground, and asked how many tiles requires a minimum?
Topic Analysis:
This is a fundamental problem, any more difficult algorithm is not involved.
First we look at, in accordance with the requirements of title to tiling, we finally came out of the shop is also a rectangle.
We set out our shop and rectangular length and width, respectively n 'and m', and satisfies n '≥ n and m' ≥ m.
And we know, n 'and m' are be a divisible. So we just need to find the smallest n 'and m' on it.
By analyzing the minimum we can get n '= ⌈n / a⌉ × a , minimum m' = ⌈m / a⌉ × a . (Wherein ⌈⌉ represents rounding up)
so we can easily implement the codes:

#include <bits/stdc++.h>
using namespace std;
long long n, m, a;

int main() {
    cin >> n >> m >> a;
    cout << ( ( (n+a-1)/a ) * ( (m+a-1)/a ) ) << endl;
    return 0;
}

  

Guess you like

Origin www.cnblogs.com/mooncode/p/11027611.html