概述
从今天起要开始自己的Codeforces之旅了,
虽然自己目前很菜,
希望通过刷题可以提高自己的能力。
【题目来源】:http://codeforces.com/problemset/problem/1/A
【题目描述】: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.
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).
Write the needed number of flagstones.
6 6 4
4
【题目分析】:广场面积为n*m平方米,现有边长为a米的砖块,问至少需要多少砖块可把广场填满。
分别把长度所需砖块个数与宽度所需砖块个数算出来,计算乘积即可。
注意:提交的时候要注意题目中给处的数据范围,一般数据量都很大,刚开始就因为设置成整型导致结果错误。
【AC代码】
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long n,m,a,x,y;
cin>>n>>m>>a;
if(n%a>0)
x=n/a+1;
else
x=n/a;
if(m%a>0)
y=m/a+1;
else
y=m/a;
cout<<x*y<<endl;
return 0;
}
最后
以上就是土豪书包为你收集整理的Codeforces 1A. Theatre Square的全部内容,希望文章能够帮你解决Codeforces 1A. Theatre Square所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复