-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathMorellet’s-random-lines.js
33 lines (28 loc) · 1.06 KB
/
Morellet’s-random-lines.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// https://www.codingame.com/ide/puzzle/morellets-random-lines
Array.prototype.unique = () => Array.from(new Set(this));
const mapToNumbers = _ => readline().split(' ').map(Number);
const [xA, yA, xB, yB] = mapToNumbers();
const getY = (x, [a, b, c]) => -((a * x + c) / b)
const getYs = (a) => [getY(xA, a), getY(xB, a)];
const reductionByMin = (a) => a.every(n => n % Math.min(...a) === 0) ? a.map(e => e / Math.min(...a)) : a;
const sameSign = (a) => a[0] < 0 ? a.map(n => -1 * n) : a;
const eqs = [...new Array(+readline())]
.map(mapToNumbers)
.map(reductionByMin)
.map(sameSign)
.map(e => e.toString()) // Can use set only on strings.
.unique()
.map(e => e.split(',').map(Number));
let cntA = 0,
cntB = 0;
// Count how many lines the line (0,yA),(0,yB) crosses,
// if both counters are even/odd, the points in same color.
eqs.map(getYs).forEach(([_yA, _yB]) => {
if (yA === _yA || yB === _yB) {
print('ON A LINE');
quit();
}
if (yA > _yA) cntA++;
if (yB > _yB) cntB++;
})
print(cntA % 2 === cntB % 2 ? 'YES' : 'NO');