Too worrying about the house price bubble, poor Mike sold his house and rent an apartment in a 50-floor building several months ago. This building has only one elevator because it is a so called “rotten tail building”. There are always a lot of people crowding at the gate of the elevator on every floor. Many people have to climb hundreds of steps in order to save time.
After months of climbing, Mike feels that he can’t stand it any more. He wants to sue the building owner. In order to let the judge understand how terrible the situation is, he decides to write a program to simulate the running of the elevator in a day. You’d better let him copy one from you .
At first, the elevator is at the status of “idle”. If the three conditions below are all satisfied at the same time, we say the elevator is at “idle” status:
1) The elevator is stopped.
2) Nobody outside is waiting for the elevator.
3) There is nobody in the elevator or all people in the elevator are just on their destination floor.
There are an up button and a down button at the elevator gate on every floor except that only up button on the first floor, and only down button on the 50th floor. When someone wants to take the elevator, he pushes a button according to the direction he wants to go, and then wait. If the elevator is not moving towards his destination floor, he will not get in even the elevator comes and opens its door. When someone pushes a button, we say that he send a request to the elevator.
When the elevator is idle and then some requests are sent to it, it will move towards the direction from which the first request is sent. If more than one request is sent at the same time, the requests sent form the same floor where the elevator stays have higher priority. In other cases, requests which will make the elevator go up, have higher priority than the same time requests which will make the elevator go down.
Once the elevator starts moving, it keeps its moving direction until the three conditions below are all satisfied at the same time:
1) All the people in the elevator have reached their destination floor.
2) There is nobody waiting for the elevator at the elevator’s moving direction.
3) Nobody on the floor where the elevator stays wants to go towards the elevator’s moving direction.
When the three conditions above are all satisfied at the same time, if there are requests from the direction opposite to the elevator’s last moving direction, the elevator will turn around and start moving; and if there are no requests at that time, the elevator will stay there and become idle.
When the elevator reaches a certain floor, it will stop and open its door when one of the two conditions below is satisfied:
1) Someone inside the elevator wants to get off on that floor.
2) Someone on that floor wants to go towards the elevator’s moving direction.
It takes one second for the elevator to move from one floor to another.
It takes one second for the elevator to open the door or close the door.
It takes one second for people outside the elevator to get in, no mater how many people.
It takes one second for people inside the elevator go get out, no mater how many people.
The elevator can’t stop between two floors.