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;
    }
    
  • 相关阅读:
    仿苹果原生头部动画
    cookie VS sessionstorge VS localstorge
    require实现单页应用程序(SPA)
    物体position:absolute后设置left:50%发生的有趣小事
    C/JS_实现选择排序
    C/JS_实现冒泡排序
    C_求质数
    C/JS_二分法查找
    JS_高程6.面向对象的程序设计(2)创建对象_3 构造函数存在的问题
    CSS_常见布局
  • 原文地址:https://www.cnblogs.com/gidear/p/10433291.html
Copyright © 2011-2022 走看看