
-----------------------------------
Martin
Thu Oct 02, 2003 11:18 pm

University Question (Very Hard)
-----------------------------------
Here's the link to the question.

http://www.cs.uwaterloo.ca/features/programmingTeam/index.shtml#sampleProblems

if anyone has any insights...

if anyone gets it, let's just say that they'll never have a problem with bits for the rest of their life.

-----------------------------------
Catalyst
Thu Oct 02, 2003 11:40 pm


-----------------------------------
#1 or #2?

-----------------------------------
Catalyst
Fri Oct 03, 2003 12:07 am


-----------------------------------
heres #2

proc Bubble (var a : array 1 .. * of real, n : int)
    var hold : real
    for i : 1 .. n
        for k : 1 .. n - 1
            if a (k) > a (k + 1) then
                hold := a (k)
                a (k) := a (k + 1)
                a (k + 1) := hold
            end if
        end for
    end for
end Bubble
function Distance (x1, y1, x2, y2 : real) : real
    result ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
end Distance

var numCases : int
var numWithSat : int
var numStations : int

get numCases
get numWithSat
get numStations

var stationListx : array 1 .. numStations of int
var stationListy : array 1 .. numStations of int
var stationListd : array 1 .. numStations, 1 .. numStations of real
var stationListassc : array 1 .. numStations, 1 .. numStations of int

var satList : array 1 .. numWithSat + 1 of real
for i : 1 .. numWithSat + 1
    satList (i) := 100005
end for

for i : 1 .. numStations
    get stationListx (i)
    get stationListy (i)
end for


for i : 1 .. numStations
    for k : 1 .. numStations
        stationListd (i, k) := Distance (stationListx (i), stationListy (i), stationListx (k), stationListy (k))
    end for
end for

for i : 1 .. numStations
    for k : 1 .. numStations
        if (i not= k) then
            Bubble (satList, numWithSat + 1)
            for j : 1 .. numWithSat + 1
                if (stationListd (i, k) 