Maniacal Midsummer Marathon 2014 by AL, TL, JJ
Fun fact: Do you like mashing on those door-close buttons in elevators? Well, in most elevators built since the 90s, those buttons are just there to give passengers a false sense of control.
You were noticeably enraged when your friend, the lead engineer working for a large elevator firm, told you this fact. "What is this bamboozlement I've been experiencing my whole life?" you ask him. "Elevators are always so slow and lead to such long waiting times. And you blame us, the passengers for always being in a hurry and slamming on the door-close buttons. Can't you guys just design better elevators?"
He responds by telling you that behind-the-scenes, elevator companies work really hard to make elevators really efficient. The best elevator algorithm still remains a very difficult open problem. Companies even keep their own algorithms a trade secret.
That's when your entitled ass started boasting to him about easily being able to design a way better algorithm than whatever garbage his incompetent team can come up with. You quickly realize that this was a big mistake, because he actually challenged you to an elevator face-off. Being the lead engineer, he actually has the resources to pull this off. He claims that he'll give you a job at his firm if you manage to win or tie against him, but that you'll have to wax his hairy back if you lose. Being the sad, unemployed nerd you are, living with your parents and eating Cheetos off your chest every day, you have no choice but to accept his challenge to finally try and land yourself a job.
The challenge is to write a program for the computer of the elevator in a building, such that the average waiting time for passengers is minimized. There will be cameras on each floor of the building to record the waiting times of passengers. First, he'll hook your algorithm up to run for a period of time and record the results. Then, your friend will take the passenger data collected from your service period, enter it into his special elevator simulator software, and run his own company's algorithm on it. In the end, the average waiting time of your algorithm and his algorithm will be compared.
After digging through some articles online, you discovered that - big surprise! - elevator systems actually do require quite a bit of complicated mathematical theory. There's no way you'll be able to learn it all in time. Just as you were heading out to buy some wax paper, a dastardly thought suddenly goes through your mind – what if you rigged the challenge?
The day before your contest, you've secretly paid off the building
manager, having him make an announcement to everyone that the elevators
are out of service for the time period of your bet. You also told him to
seal off the doors so that only certain people can enter and use the
elevators. Why? Well, you've secretly arranged for
Your program will have the following information before the challenge:
- There are
floors in the building being serviced, uniquely labeled with an integer from to . - The elevator may change directions at any time. The time it takes to change directions is negligible.
- The elevator travels at a constant speed of
( , is a real number) floors per second. While the elevator is traveling, it may stop at any floor, either to remain idle, or to pick up/drop off passengers. - The elevator may stop for as long as possible on a floor. Standard
regulations require elevator doors to open for at least
( , is an integer) seconds each time. This means that if an elevator is told to stop for fewer than seconds, it will simply remain idle with its doors closed, and no passengers may get on or off. Note that your passengers are bribed, so they will take no more than total seconds to get on and off. They will never delay the door-close by hitting the door-open button or standing in the way of the sensors. - There are
passengers that need to be serviced. The passengers are each uniquely labeled with an integer from to . - The following information is known about the passengers you've
bribed:
- At
seconds ( , is an integer), passenger will arrive at the elevator doors on floor . - Passenger
would like to go to floor . - Passengers will be patient. That is, a passenger will never abandon their waiting spot until the elevator arrives.
- If the elevator doors are open on a passenger's initial floor
, then the passenger will immediately step into the elevator. - Similarly, if a passenger is on the elevator which is currently
on their designated floor
with its doors open, then the passenger will immediately step out of the elevator. For example, if the elevator doors open at , then we consider the time of all passengers getting off during this stop to also be . - If an elevator door opens at
and closes at , and a passenger arrives at during that range, then they may enter the elevator if and only if .
- At
The waiting time experienced by passenger
The average waiting time is the sum of the waiting times of all of the
passengers, divided by the number of passengers
Initially, the elevator is on floor
Input Specification
The
The
The following
Output Specification
In order to control the elevator, you must first become familiar with the two commands of the elevator's system. They are the following:
Command | Format | Description |
---|---|---|
GO b | G b |
Move the elevator from its current floor to floor |
STOP t | S t |
Stop the elevator for |
Each line of the output should describe an elevator command in one of
the two formats listed above. The commands will be performed back to
back (with the slight exception of those that follow a GO
command,
which will be performed at the next available whole number second after
the elevator arrives at its floor), and will control the behavior of the
elevator from start to finish.
Sample Input
10 2 3.0
4
0 2 5
2 1 10
4 5 10
21 10 4
Sample Output
S 3
G 2
S 2
G 5
S 2
G 10
S 11
G 4
S 2
Explanation
There are
Time | Command | Description | Passenger Status | |||
---|---|---|---|---|---|---|
STOP 3 |
The elevator is on floor Meanwhile, passenger |
|||||
Passenger |
||||||
GO 2 |
The elevator travels at Thus, the elevator will only take |
|||||
STOP 2 |
The elevator is on floor |
|||||
GO 5 |
The elevator travels to floor its total time to reach floor |
|||||
STOP 2 |
The elevator is on floor Also, passenger |
|||||
GO 10 |
The elevator goes to floor |
|||||
STOP 11 |
The elevator is on floor Afterwards, the elevator idles to wait for passenger |
|||||
Passenger |
||||||
GO 4 |
||||||
STOP 2 |
The elevator doors open on floor |
|||||
In the above table:
Passenger
Passenger
Passenger
Passenger
The average waiting time is
Scoring
For each test case, let's say the average waiting time for passengers
during your lift service is
Then, your score out of
, if any of the following holds true:- The output format is incorrect (lines do not follow one of the two formats listed above); or
- Not all passengers have an opportunity to get on and off the elevator to reach their destination.
- between
and , if .- Your program scores
base points for getting any valid way of moving all passengers to their designated floors, plus an additional score that is determined from a rational scale based on the values and . - Specifically, your score will be
, rounded to the nearest integer.
- Your program scores
(or over), if .
Here,
Experimentation
For testing purposes, you are provided with a program to simulate the activities of the elevator and passengers. The simulator program simulator.py will accept the following command line options:
-h
will give a brief overview of the available options-i INFILE
loads the input file in the input format as described above-cmd CMDFILE
loads the command file in the output format as described above-log LOGFILE
specifies the file into which to dump information about the simulation. This is optional, as the same information will always be logged in standard output.
Comments