#FT0000094. Đánh chặn tên lửa (Missile Interception)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đánh chặn tên lửa (Missile Interception)
Missile Interception
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
A country has one missile interception system protecting it against an enemy attack. The system detects incoming missiles in their arrival order, numbered from to . Each missile has an integer height and an integer speed, both positive.
The first intercepted missile may have any height or speed. After intercepting a missile, the system can choose a missile arriving later only if both of the following conditions hold:
- The next missile's height is not greater than the height of the previously intercepted missile.
- The next missile's speed is not greater than the speed of the previously intercepted missile.
Equivalently, for selected indices , a valid plan satisfies and for every . Equality is permitted. Each missile may be intercepted at most once.
The system first maximizes the number of intercepted missiles. Different optimal plans may exist. Two plans are different whenever their selected sets of missile indices differ. If more than one optimal plan exists, the system chooses one of them uniformly at random.
Determine the maximum number of missiles the system can intercept and the probability that each missile belongs to the randomly chosen optimal plan.
Input
- The first line contains the integer , the number of incoming missiles.
- Each of the following lines contains two integers and , the height and speed of missile , respectively. These lines follow the order in which the missiles arrive.
Output
- The first line must contain one integer: the largest possible number of intercepted missiles.
- The second line must contain exactly real numbers in the order of missiles . The -th number is the probability that missile is included when an optimal plan is chosen uniformly at random.
Each probability must be in . The absolute error of each probability must not exceed . Printing, for example, digits after the decimal point is sufficient.
Original scoring rule: 40% of each test case's score is for the integer on the first line; the other 60% is for all probabilities on the second line. These two components are scored independently.
Subtasks
- Subtask 1 (20 points): ; and for every . The number of optimal interception plans is finite and representable by C++
double. - Subtask 2 (30 points): ; and for every . The number of optimal interception plans is finite and representable by C++
double. - Subtask 3 (50 points): ; and for every . The number of optimal interception plans is finite and representable by C++
double.
Examples
Example 1
Input
4
3 30
4 40
6 60
3 30
Output
2
0.33333 0.33333 0.33333 1.00000
Explanation
The four missiles have equal to , , , and , respectively.
No two missiles among the first three may be intercepted consecutively in arrival order because their heights and speeds increase. However, each of these missiles can precede missile , whose height and speed are not greater.
Thus, the three optimal plans are , and . Every such plan intercepts exactly missiles, and no longer plan exists. Each of missiles , , and belongs to exactly one of the three plans, so its probability is . Missile belongs to all three and therefore has probability .
Example 2
Input
4
5 5
4 4
5 4
3 3
Output
3
1.00000 0.50000 0.50000 1.00000
Explanation
Missile has height and speed and can precede either missile with or missile with . Missiles and cannot be intercepted consecutively in that order because the height would increase from to .
Exactly two longest plans exist: and , each of length . Missiles and appear in both plans and have probability . Missile appears only in the first, and missile only in the second, so each has probability .