A. Theatre Square
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
inputCopy
6 6 4
outputCopy
4
题意:很简单,
AC:
#include<stdio.h>
#include<string.h>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
int main()
{
int n,m,a;
cin>>n>>m>>a;
ll x=ceil(n*1.0/a)*ceil(m*1.0/a);
//ll y=ceil(m*1.0/a);
cout<<x<<endl;
return 0;
}
ceil,,math函数,向上取整
错误代码:虽然看起来很复杂,我不过是把情况都拿出来讨论输出了,即使我用了long long,还是在1000000000 1000000000 1 这个例子中爆掉,codeforce说 带符号整数溢出。不知何意,但上面点的代码就不会,这个错的时候我还想着这题大概率要用高精度乘法,呵呵呵,!!!!
#include<stdio.h>
#include<string.h>
#include<vector>
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
int main()
{
int n,m,a;
cin>>n>>m>>a;
ll sum;
if(n%a==0)
{
if(m%a==0)
{
//ll sum;
sum=n/a*(m/a);//带符号整数溢出
cout<<sum<<endl;
}
else
{
sum=n/a*(m/a+1);
cout<<sum<<endl;
}
}
else
{
if(m%a==0)
{
sum=m/a*(n/a+1);
cout<<sum<<endl;
}
else
{
sum=(n/a+1)*(m/a+1);
cout<<sum<<endl;
}
}
return 0;
}