Problem #339
✰ - click to bookmark
★ - in your bookmarks
Tags:
c-1
puzzle
simulation
This small problem I've found in some old magazine, regretfully I don't remember which, it was decades ago. Probably "Science and Life" for some 198x issue.
There is a Parking Lot, in a form of linear space of length W. Cars, when arrive, can park anywhere on it,
taking exactly 1 unit of space. Of course they only can park in empty "gaps".
It is obvious that Parking Lot of length W can accommodate up to int(W) cars. However car drivers are
careless and park they cars quite randomly, not necessarily aligning them to integer intervals.
For example, regard W = 2.5. In theory we can place 2 cars here. However if the first driver to arrive
parks immediately in the center of it, then only two small gaps 0.75 units wide are left on both sides - so
the second car won't fit.
So, how many cars on average can be parked on the lot of length W?
W = [0, 1) - i.e. from 0 inclusive to 1 non-inclusive - it is 0 cars.W = [1, 2) - it is 1 car.W = [2, 3) things become complicated, number of cars grows from 1 to 2 smoothly (perhaps as N = 3 - 2 / (W - 1))Input single value W - size of the parking lot (not exceeding 50).
Answer single value N - average number of cars which could be parked with precision no worse than 1%.