programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# finding of n and s in rectangle

Vital Jays
Greenhorn
Posts: 27
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.

Tony Docherty
Bartender
Posts: 3271
82
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
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
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
There is nothing wrong with s, but the formula for n is not quite correct.

Vital Jays
Greenhorn
Posts: 27
• 1
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
Indeed!

And mind you: (a/c) is allright, but only as long as a and c are integers (or shorts, longs et cetera)