在网格中找到所有可能的矩形(不包括正方形) [英] Find all the possible Rectangles(excluding squares) in a Grid

查看:151
本文介绍了在网格中找到所有可能的矩形(不包括正方形)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个矩形(甚至N×N的正方形)H×W,找到所有可能适合H×W(或N×N)的矩形(正方形除外).

我的导师汤匙给了我这种表达,但让我们自己去弄清楚它为什么起作用以及如何起作用.


Given a rectangle(or even a square of N x N) H x W, find all the possible rectangles (excluding squares) that can fit into H x W (or N x N).

My tutor spoon fed me this expression but left it up to us to figure out why and how it works.


for H = 1 to Height
   for W = 1 to Width
      totalRect += (H x W) - Math.min(H,W)
   next
next



这种表达方式的简单性绝对是美丽的,并且可以完美地发挥作用.但是我无法弄清楚它为什么起作用,甚至无法起作用(我无法得出它).谁能帮助我解决这个问题?

谢谢



The expression is absolutely beautiful in its simplicity and it works perfectly. But I cant figure out why or even how it works ( I can''t derive it). Anyone out there not of a lesser mind that can help me figure this out?

Thanks

推荐答案

>
Cyber​​Samuraiii写道:
CyberSamuraiii wrote:

但留给我们自己去弄清楚为什么以及如何运作.

but left it up to us to figure out why and how it works.



因此,弄清楚其原因和工作方式.如果您不能分析现有代码,那么您绝对会成为程序员.



So, figure out why and how it works. If you can''t analyze existing code, you''ll absolutely suck as a programmer.


Cyber​​Samuraiii写道:
CyberSamuraiii wrote:

该表达式简单易用,非常完美.

The expression is absolutely beautiful in its simplicity and it works perfectly.


我敢打赌,我的20美分目前无法使用. :)


I bet my 20 cents it does''t work as it stands. :)


这篇关于在网格中找到所有可能的矩形(不包括正方形)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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