测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A13589. Uncle Bogdan and Projections

编程题 普及/提高-

题目描述

After returning to shore, uncle Bogdan usually visits the computer club "The Rock", to solve tasks in a pleasant company. One day, uncle Bogdan met his good old friend who told him one unusual task...

There are $n$ non-intersecting horizontal segments with ends in integers points on the plane with the standard cartesian coordinate system. All segments are strictly above the $OX$ axis. You can choose an arbitrary vector ( $a$ , $b$ ), where $b < 0$ and coordinates are real numbers, and project all segments to $OX$ axis along this vector. The projections shouldn't intersect but may touch each other.

Find the minimum possible difference between $x$ coordinate of the right end of the rightmost projection and $x$ coordinate of the left end of the leftmost projection.

输入格式

The first line contains the single integer $n$ ( $1 \le n \le 2000$ ) — the number of segments.

The $i$ -th of the next $n$ lines contains three integers $xl_i$ , $xr_i$ and $y_i$ ( $-10^6 \le xl_i < xr_i \le 10^6$ ; $1 \le y_i \le 10^6$ ) — coordinates of the corresponding segment.

It's guaranteed that the segments don't intersect or touch.

输出格式

Print the minimum possible difference you can get.

Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$ .

Formally, if your answer is $a$ and jury's answer is $b$ then your answer will be considered correct if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$ .

输入输出样例

输入 #1
3
1 6 2
4 6 4
4 6 6
输出 #1
9.000000000
输入 #2
3
2 5 1
4 6 4
7 8 2
输出 #2
6.333333333
输入 #3
2
1 3 1
4 7 1
输出 #3
6.000000000

说明/提示

In the first example if we project segments along the vector $(1, -1)$ then we get an answer $12-3=9$ and (it can be proven) it is impossible to get less.

![](/uploads/acgo/image/3bc771c8c2235be8_e1c0172619b1.jpeg)It is optimal to project along the vector $(1, -3)$ in the second example. The answer is $8\frac{2}{3}-2\frac{1}{3}=6\frac{1}{3}$

![](/uploads/acgo/image/05c7ae309dc65e13_0c6cba13a392.jpeg)
上一题 去做题 下一题