0128. Common Measure

Имя входного файла: common.in
Имя выходного файла: common.out
Ограничение по времени: 500 ms
Ограничение по памяти: 64 megabytes

The common measure of two segments is length of maximal segment such that any of the two segments can be obtained by repeating it several times on a straight line. E. g. the common measure of segments with lengths sqrt(50) and sqrt(8) is sqrt(2).

Of course, not all pairs of segments have common measure. For example, the side and the diagonal of a square are incommensurable.

You have to check whether two given segments have a common measure and to find it in the case of positive answer.

Input file

Input file contains eight integers, all of them not exceeding 104 by an absolute value: x(1,source), y(1,source), x(1,but), y(1,but), x(2,source), y(2,source), x(2,but), y(2,but) – coordinates of the ends of the first and second segments respectively. The segments will not have zero length.

Output file

The first line must contain either YES or NO. In the case of positive answer, output in the second line the common measure with the precision of six digits after decimal point.

Examples:

common.incommon.out
0 0 2 2 10 15 15 10YES 1.414214
0 0 0 1 0 0 1 1NO


Источник: Petrozavodsk Summer 2003. Blitz Kontest, Monday, August 25
Автор: Andrew Lopatin, Nick Durov

Обсудить       Отправить решение



Версия для печати