2018-12-15 acm日常 CodeForces

A - Problem A CodeForces - 1A

Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city’s anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.

What is the least number of flagstones needed to pave the Square? It’s allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It’s not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

Input
The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).

Output
Write the needed number of flagstones.

Examples
Input
6 6 4
Output
4

之前错误的地方,把输出放在了判断的条件外,就直接wa了。

//优化后
#include<iostream>
using namespace std;
int main()
{
	int n, m, a;
	long long s, x, y;
	cin >> n >> m >> a;
	/*if (a >= n&&a >= m)
	{
		s = 1; cout << s;
	}
	else*/
	
		x = n / a;
		if (n%a)
		{
			x++;
		}
		y = m / a;
		if (m%a)
		{
			y++;
		}
	
	cout << x*y << endl;
    return 0;
}

之前的代码ac,但是不简洁。

//优化前
#include<iostream>
using namespace std;
int main()
{
	int n, m, a;
	long long s, x, y;
	cin >> n >> m >> a;
	if (a >= n&&a >= m)
	{
		s = 1; cout << s;
	}
	else
	{
		x = n / a;
		if (n%a)
		{
			x++;
		}
		y = m / a;
		if (m%a)
		{
			y++;
		}
        cout << x*y << endl;
	}
	
    return 0;
}
原文地址:https://www.cnblogs.com/gidear/p/10433291.html