Programming Olympics / TASK: Blocks

Programming Olympics

Learn Computer Programming Here ... and maybe represent Ireland?

You are not logged in.

#1 2008-11-05 21:21:07

admin
Administrator
Registered: 2008-11-02
Posts: 56

TASK: Blocks

Trevor's table has finally collapsed! He had been piling books, boxes and computer hardware onto it for years, and just yesterday, the left leg of the table splintered, causing a big mess.

He now wants to replace the leg with something tougher, so goes to the local quarry to get some stone blocks. Unfortunately, Trevor can only afford two blocks, and must find two such blocks so that the sum of their sizes adds up to exactly one metre (1000mm), since the other table leg is this height. The quarry has a long list of all the sizes of the stone blocks they currently have on sale.

Write a computer program to help Trevor find two blocks whos sizes sum to 1000. If there are multiple solutions, choose the solution where the size of largest stone is minimised.

E.g. 100 & 900 is a solution, and 400 & 600 is also a solution, but 400&600 is better because 600<900.


Example input:
How many stones are in the quarry? 10
What are the sizes of the 10 stones? 200 250 401 708 358 100 150 330 999 850

Example output:
Trevor should buy a size 150 and a size 850

Offline

 

#2 2008-11-20 16:19:44

Paulmg
New member
Registered: 2008-11-20
Posts: 5

Re: TASK: Blocks

Do we assume that there is a solution in every input?

Offline

 

#3 2008-11-21 12:14:17

admin
Administrator
Registered: 2008-11-02
Posts: 56

Re: TASK: Blocks

Hi Paul,

if your program does not find a solution, you can print a message such as "No two blocks can be found to sum to 1000".

Ciarán.

Offline

 

#4 2008-12-25 17:44:58

moa
New member
From: Newry
Registered: 2008-12-25
Posts: 6

Re: TASK: Blocks

Do we assume that there can be an infinite number of stones in the quarry?

Offline

 

#5 2008-12-27 22:50:29

admin
Administrator
Registered: 2008-11-02
Posts: 56

Re: TASK: Blocks

Hi,

well you can assume all sizes will be positive integers, which means there is only a finite number of relevant sizes to consider.

Offline

 

#6 2011-12-04 14:57:43

Zoltem
New member
From: Ahoskie
Registered: 2011-11-29
Posts: 1
Website

Re: TASK: Blocks

hi all members.. i just joined this forums....hope that i find this forum as great community...


When I had monster questions with drafting my letter point-deviceI bought valuable cover letter writing services  underground.

Offline

 

Board footer

viewtopic

Powered by PunBB
© Copyright 2002–2008 PunBB