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;
    }
    
  • 相关阅读:
    二阶段任务分配
    二阶段12.2
    针对提出的意见的改进
    一阶段spring(小呆呆)团队评分
    搜狗输入法使用感受
    省呱呱典型用户和用户场景
    省呱呱意见评论
    11/21
    11/20小组计划
    11/19小组计划
  • 原文地址:https://www.cnblogs.com/gidear/p/10433291.html
Copyright © 2011-2022 走看看