#GL0000285. Các tầng của tòa nhà (Skyscraper Floors)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các tầng của tòa nhà (Skyscraper Floors)
Skyscraper Floors
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A building has floors numbered from through . You must move a piece of furniture from floor to floor , using only elevators, never the staircase.
There are elevators. Elevator first stops at floor and then at all floors , for nonnegative integers , as long as the floor is less than . Each elevator can travel in either direction between any two of its stops. You may transfer between elevators at any floor served by both.
Determine whether the furniture can reach floor from floor . If the floors coincide, no elevator ride is needed.
Input
- The first line contains four integers : number of floors, number of elevators, start floor and destination floor.
- The next lines each contain two integers : stop interval and starting floor of elevator .
Output
Print exactly one of the two lines:
It is possible to move the furniture.if the transfer is possible.The furniture cannot be moved.otherwise.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input
22 4 0 6
3 2
4 7
13 6
10 0
Output
It is possible to move the furniture.
Explanation
One possible transfer sequence is 0 → 20 using the elevator stopping at multiples of 10, then 20 → 11 on the elevator starting at 2 with step 3, then 11 → 19 on the elevator starting at 7 with step 4, and finally 19 → 6 on the elevator starting at 6 with step 13. All transfer floors belong to both adjacent elevators.
Input
1000 2 500 777
2 0
2 1
Output
The furniture cannot be moved.
Explanation
The first elevator serves only even floors while the second serves only odd floors. Floor 500 belongs only to the first elevator and 777 belongs only to the second; they have no common stopping floor, hence transfer is impossible.