• Post Reply Bookmark Topic Watch Topic
  • New Topic

finding of n and s in rectangle  RSS feed

 
Vital Jays
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Positive integers A, B, C are given.  The maximum possible number of squares with side C (without overlays)  is placed on the rectangle of size A × B. The task is  to  find the number of squares placed on the rectangle, as well as the area of the unoccupied part of the rectangle.

My  try  is  following:

n is  number of  squares and side c is  the  side  of  square  here. Would you help me  to  find  s here.
Thank you in  advance.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question isn't related to Java it's about the algorithm so this isn't really the place to post such a question.

Having said that your first problem is to find 'n', so I'd make sure that is correct before moving on to finding s. If your rectangle is 5 x 3 and the size of your squares are 1 then how many squares fit into the rectangle. BTW the way it isn't 3.

you should really work this out in your head (or get some paper and cut out some squares and try fitting them into a rectangle) before running your code to check the code is producing the correct answer.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Vital,

have a careful look at line 8.
But apart from that: having a, b, c and n, what is the problem with determining s?
 
Vital Jays
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Tony Docherty
if  it is only about algorithm i  guess for  the  future i  will post  such questions in the forum Beginning Java.
thanks

Piet Souris
I  found s,  but i wasn't  sure if I've found the  right solution , so  i wonder if  someone can check it or  propose another solution
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing wrong with s, but the formula for n is not quite correct.
 
Vital Jays
Greenhorn
Posts: 27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to Piet Souris

Oh  I see,


a/c - is the number of squares on the side a

b/c -  is the number of squares placed on the side b

* shows total number of squares
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed!

And mind you: (a/c) is allright, but only as long as a and c are integers (or shorts, longs et cetera)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!