在c中解决这样的问题的方法是什么? [英] What is the method to solve a problem like this in c.

查看:79
本文介绍了在c中解决这样的问题的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

剩下一个I * j米的矩形图,我们剩下一个*米的方块。一位建筑师计划使用方块,所需的方形数量是多少,如果需要我们可以覆盖更多矩形情节,但不应该打破方格。



我尝试过:



我试过通过计算矩形区域并与方形区域比较,如果方形区域是我继续我的过程并计算方块,并在某些条件下我添加了一些其他方块以覆盖矩形图。

A rectangle plot of I*j metres is left and we have a*a metres square blocks left.An architect planned to use square blocks,what is the required number of square to cover rectangle plot and if required we can cover more rectangular plot but should not break squares.

What I have tried:

I have tried by calculating rectangular area and compared with square area if square area is I continued my process and counted square blocks and in certain conditions I added some other square blocks to cover rectangular plot.

推荐答案

区域不重要,矩形 i,j 尺寸很重要。

你知道,如果你是幸运的 a 完全划分 i ,所以你需要(i / a)(整数除法)在 i 方向上加上方格。

另一方面,如果你没那么幸运那么分区中有剩余部分和你在 i 方向上再一个方格,即(i / a + 1)方块。您可以为 j 方向生成类似的参数,并轻松找出所需的方块数。
Area isn't that important, rectangle i,j dimensions are important.
You know, if you are lucky a divides exactly i, so you need exactly (i/a) (integer division) squares int the i direction.
On the other hand, if you're not so lucky then there is a remainder in the division and you need one more square, namely (i/a + 1) squares in the i direction. You can produce a similar argument for the j direction and easily figure out how many squares you need.


这看起来像是作业,所以没有代码:

首先计算你当前矩形中可以容纳的最大正方形,然后看看剩下的是什么。这将是一个矩形区域,因此您可以使用相同的处理来生成下一个方格。

如果您知道方形的最小尺寸,您可以将其与矩形的大小进行比较来决定如果你应该超过矩形以适合正方形。
This looks like homework, so no code:
Start by calculating the biggest square you can fit in your current rectangle, then look at what is left. That will be a rectangular area, so you can use the same processing to generate the next square.
If you know the minimum size of a square, you can compare that against the sizes of the rectangle to decide if you should just be exceeding the rectangle to fit in a square.


Quote:

什么是在c中解决这样的问题的方法。

What is the method to solve a problem like this in c.



与任何其他编程语言相同。



拿一张纸用纸和铅笔解决问题并找到数学。

你通过一个程序解决了这个问题,该程序就是你的算法。您需要以机械方式(类似计算机)写下这些步骤。该程序将遵循这些步骤。



作为程序员,你的工作是创建算法来解决具体问题,你不能依赖别人永远为你做这件事,所以有一段时间你必须学会​​如何做。而且越快越好。

当你要求解决方案时,就像试图通过培训其他人来学习开车一样。

创建算法基本上是找到数学并做出必要的调整以适应你的实际问题。



我们不做你的家庭作业。


The same as with any other programming language.

Take a sheet of paper and a pencil and solve the problem by hand and find the maths.
You solved the problem by following a procedure, that procedure is your algorithm. You need to write down the steps in a mechanical manner (computer like). The program will follow those steps.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.

We do not do your HomeWork.


这篇关于在c中解决这样的问题的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆