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;
    }
    
  • 相关阅读:
    Intel 编译器 线程安全检查 真心的很详细 转
    当前软件设计分析
    当代并行机系统
    多人游戏服务器
    ACE源代码目录结构
    (转!)Z buffer和W buffer简介
    数据库-视图(View)详解
    推荐一个vs自带工具分析代码的复杂度
    SCOPE_IDENTITY的用法
    vs2013开发调试cocos2d-x-Lua工程项目
  • 原文地址:https://www.cnblogs.com/gidear/p/10433291.html
Copyright © 2011-2022 走看看