-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavascript.js
46 lines (46 loc) · 1.45 KB
/
Javascript.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
34
35
36
37
38
39
40
41
42
43
44
45
46
while (true) {
var inputs = readline().split(" ");
const x = parseInt(inputs[0]);
const y = parseInt(inputs[1]);
const humanCount = parseInt(readline());
let listHuman = [];
for (let i = 0; i < humanCount; i++) {
var inputs = readline().split(" ");
const humanId = parseInt(inputs[0]);
const humanX = parseInt(inputs[1]);
const humanY = parseInt(inputs[2]);
listHuman.push({ id: humanId, x: humanX, y: humanY });
}
const zombieCount = parseInt(readline());
let listZombie = [];
for (let i = 0; i < zombieCount; i++) {
var inputs = readline().split(" ");
const zombieId = parseInt(inputs[0]);
const zombieX = parseInt(inputs[1]);
const zombieY = parseInt(inputs[2]);
const zombieXNext = parseInt(inputs[3]);
const zombieYNext = parseInt(inputs[4]);
listZombie.push({ id: zombieId, x: zombieX, y: zombieY });
}
h = findZombieCloserHuman(listHuman, listZombie);
console.log(h.x, h.y); // Your destination coordinates
}
function findZombieCloserHuman(humans, zombies) {
distMin = Infinity;
humanToProtect = null;
for (let i = 0; i < humans.length; i++) {
for (let j = 0; j < zombies.length; j++) {
let h = humans[i];
let z = zombies[j];
let d = distance(h.x, h.y, z.x, z.y);
if (d < distMin) {
distMin = d;
humanToProtect = h;
}
}
}
return humanToProtect;
}
function distance(x1, y1, x2, y2) {
return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2);
}