zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    el-upload怎么拿到上传的图片的base64格式
    浮动到表格中某一行,根据改行信息高亮某区域文字,并设置对应滚动高度,使高亮文字出现在当前视野
    IE浏览器报Promise未定义的错误
    el-input为数字时验证问题
    Tomcat
    redis
    JSON
    JQuery基础
    JQuery高级
    Git学习(二)
  • 原文地址:https://www.cnblogs.com/gidear/p/10433291.html
Copyright © 2011-2022 走看看