Submit | All submissions | Best solutions | Back to list |
BOWORMS - G - Worms |
PROBLEM G
WORMS
It’s the most expected day in the Astounding Confederation of Manzania. Finally, the long awaited games will begin, and the people of this proud nation want to present the best aperture ever made for this kind of events.
Thousands of proudly manzanians will participate in the ceremony that will be held in the historical Manzan´a stadium. Dancers, singers, musicians, lots of color and (real) fireworks all over the place, and of course the national animals can’t be absent: the worms, loyal fellows who fought bravely and helped to forge the country.
During the show, several performers will march in straight lines inside a rectangular area of the main field, covered with worm costumes of bright colors and several meters long (as the real worms are too small to be visible from the gallery), in a section called “The Dance of the Worms”.
No detail has been left unattended. At least that is what you thought before hearing a hard discussion between the president of the organization committee, and the artistic director. The Dance of the Worms is in serious trouble! At the beginning of the dance, all the performers in their worm costumes will start to walk in the already designed roads on the field. But the lines cross, and nobody had payed attention to properly synchronize the start, and some of the worms can collide, bringing chaos and despair to the otherwise perfect ceremony. Now, the artistic director has caught you to help him to solve the mess. Once the worms are inside the field, they can’t be stopped (they can’t be fired, because of all the legal stuff). They have trained to do the march at 1m/s, with their heavy costume. In order to allow all the worms to walk smoothly on the field, some of them will have to be delayed and will begin the march some seconds later than the others. The delay for each worm has to be an integer number, otherwise they can’t count it. The organization, of course, does not want to extend The Dance of the Worms too much ; after all, there are other performances. So, the first thing to know is how much time will the worms be delayed to let all of them march without colliding each other.
You will be given the dimensions of the field where the march will take place, the length of all the worms, and the planned trajectories.
Input
The input contains several test cases. The first line of a test case contains one N indicating the number of worms (2 <= N <= 10). The next line will contain three integers W, H and L indicating respectively the width and length of the field in meters (3 <= W,H <= 50), and the length of the worm costume also in meters (1 <= L <= 10).
Each of the N following lines contains two integers X0, Y0, indicating the coordinates of the origin (X0, Y0) of the straight trajectory for each worm. All trajectories are parallel to one of the borders. The origin will always be located in one border of the field, but never in the corners, and will be different for each worm.
For considering the collisions, you can assume that if one worms arrives at one point at the same time that another worm is leaving that point, no collision will happen. The end of input is indicated by a line containing only one zero.
Output
For each test case in the input, your program must print a single line, containing the sum of all the delays that must be added to the worms to ensure a perfect ceremony.
Sample Input
3
8 8 2
2 0
3 0
8 7
3
8 8 1
2 0
3 0
8 7
0
Sample Output
1
0
Added by: | Alvaro Javier Medina Balboa |
Date: | 2010-05-25 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | C C++ 4.3.2 CPP JAVA |