#P3. [Sleeping Cup #1] Moving like a spider
[Sleeping Cup #1] Moving like a spider
Person in Charge
Attention
This problem requires file I/O (spider.in
/ spider.out
).
Problem Description
An image is available here. If not visible, download it from the "Attachments" section.
As shown in the image, this is a spider web with the following elements:
- Central point , marked in yellow on the left side of the figure;
- rays emanating from (only are drawn in the figure), labeled as lines , , , ..., ;
- Multiple concentric circles centered at (only are drawn in the figure, with partial arcs shown), labeled as circles , , , ...;
- Intersection points formed by the circles and rays (excluding ). The intersection of circle and ray is denoted as . For example, the top-right intersection in the figure is .
There are spiders moving on this web, with their initial positions given (guaranteed not to be , so they can all be represented by coordinates).
Each spider can move multiple times (the number of moves is up to you, including 0 moves). Generally, there are possible directions for each move. When starting from :
Direction | Visualization | Destination | Energy Cost | Special Cases |
---|---|---|---|---|
Up | Move along the ray away from | (1) | ||
Down | Move along the ray toward | (2) | ||
Left | Move clockwise along the circle | (3) | ||
Right | Move counterclockwise along the circle | (4) |
The special cases (last column) are:
- If the starting point is (in which case the only possible move is "up"), the destination can be any of , chosen by you.
- If , the destination will be .
- If , the destination will be .
- If , the destination will be .
Now, these spiders need to gather at a meeting point (either or an intersection point). Your task is to choose an optimal meeting point and plan the movement paths for each spider to minimize the total energy cost, then output this minimum total energy.
Input Format
First line: Four positive integers, .
Next lines: The -th line contains two integers , representing the initial position of the -th spider.
Output Format
One integer: The answer.
Samples
3 7 9 8
0 2
6 4
0 5
32
2 2 3 5
0 1
1 1
3
7 11 63599913 20656382
9 9
1 11
6 4
0 4
1 15
2 11
6 20
2393965956
Explanation for Sample 1
An optimal solution is to choose as the meeting point:
- Spider moves along (3 "up" moves), costing ;
- Spider moves along (1 "right" move and 1 "up" move), costing ;
- Spider stays in place, costing .
The total cost is .
Explanation for Sample 2
An optimal solution is to choose as the meeting point:
- Spider moves along (1 "down" move and 1 "up" move), costing ;
- Spider stays in place, costing .
The total cost is .
Data Range
For of the data: , , , .
Attachments
Download the files here.
Official Solution
相关
在下列比赛中: