Bricks problem

Post here if you don't find any other place for your post. But please, stay on-topic: algorithms, programming or something related to this web site and its services.

Moderator: Board moderators

Post Reply
globi
New poster
Posts: 15
Joined: Wed Apr 23, 2003 2:44 pm
Location: Warsaw
Contact:

Bricks problem

Post by globi »

I'm unable to solve this problem correctly. Please help me:

You have chess board of size N x M and a lot of bricks of size K x 1.
How many bricks can you place on this board (brick edges must be
pallarel to board edges)

Sample data:
N = 10, M = 10, K = 4
RESULT = 24

N = 8, M = 5, K = 5
RESULT = 8
karu
New poster
Posts: 5
Joined: Tue Jun 13, 2006 5:31 am
Location: New Zealand
Contact:

Post by karu »

Here is what I would do (in C++):

Code: Select all

int main(){

//in the comments i assume m is the horizontal dimension and n is the vertical dimension

int n, m, k;

cin>>n>>m>>k;

int maxn=n/k;//maximum number of bricks that can be laid down the board
int maxm=m/k;//maximum number of bricks that can be laid across the board

//example of above code: for m=10 and k=4, maximum number of bricks that can be laid across is 2, since 4*2 <= 10 and 4*3 > 10 (so 2 will fit and 3 wont)

int numbricksnfirst=m*maxn+(n-k*maxn)*maxm;//number of bricks we can place if we fill down first then fill up the gap at the bottom
int numbricksmfirst=n*maxm+(m-k*maxm)*maxn;//number of bricks we can place if we fill across first then fill up the gap on the right

int result=numbricksnfirst;
if(numbricksmfirst>result) result=numbricksmfirst;

cout<<result<<endl;

}
Post Reply

Return to “Other words”