Back
Close

Hospital Emergency

Statement

 Goal

You are a newly hired nurse at the ER, alarms are going off all over the place.

You have to find the distance to the alarm closest to you (in a direct line), except if it is an emergency alarm, then you have to go there first. If more than one emergency alarm goes off, then you find the distance to the nearest emergency alarm.

If there is an emergency, emergency will be either "Alarm", "Emergency", or "Priority". If no emergency it will be empty. All emergencies are equal, the is always only one solution.

EXAMPLE
Input
0 0
3
3 4 Emergency
4 2 Alarm
1 1

Output
4.5

HOW TO DO IT
You are at location (0,0),

There are 3 alarms at location (3,4), (4,2), and (1,1), the first two are emergencies

the direct distance to the first alarm can be calculated as sqrt((0-3)^2+(0-4)^2) = 5 rounded to 5.0
the second one 4.47213595499958 rounded to 4.5
the third one 1.4142135623730951 rounded to 1.4

The correct distance for the answer is: 4.5, because the first two alarms are both emergencies and the second one is the closest
Input
1st line x y - Your location
2nd line n - The number of alarms
next n lines alarm consisting of

xi yi emergency(optional)

Everything is space separated
Output
The distance to the emergency to go to rounded to nearest 1 decimal, e.g. 1.0 or 2.3 or 23453.8

There is always only 1 correct answer, e.g. never two alarms with same distance and emergency
Constraints
0 <= x < 2147483647
0 <= y < 2147483647
0 <= xi < 2147483647
0 <= yi < 2147483647
0 <= n < 10
Example
Input
0 0
1
3 4
Output
distance: 5.0

Game modes
Fastest, Shortest, Reverse

Test cases
Start 0 easy result Test
Input
0 0 1 3 4
Output
distance: 5.0

Same as test case - Just multiply 10 Validator
Input
0 0 1 40 30
Output
distance: 50.0

If emergency Test
Input
0 0 3 6 8 Emergency 0 1 0 0
Output
distance: 10.0

Emergency double result Validator
Input
0 0 3 12 16 Emergency 2 1 12 16
Output
distance: 20.0

Different emergency flag Test
Input
0 0 3 0 0 19 16 Alarm 4 5
Output
distance: 24.8

Same as test, other input Validator
Input
0 0 3 0 0 55 44 Alarm 4 5
Output
distance: 70.4

Standing on alarm Test
Input
7 7 4 1 1 2 2 8 8 7 7
Output
distance: 0.0

Standing on alarm different ordering Validator
Input
8 8 4 1 1 2 2 7 7 8 8
Output
distance: 0.0

Large numbers - No emergency Test
Input
65536 65536 10 17 17 9 9 107000 200000 19750 1 5 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 1999999999 2000000000 1 2000000000 0
Output
distance: 79944.9

Same as above - but other numbers Validator
Input
1 2000000000 10 17 17 9 9 107000 200000 19750 1 5 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 1999999999 2000000000 1 2000000000 0
Output
distance: 4.0

All different emergency Test
Input
10 10 5 1 1 1 100 100 Priority 11 12 Alarm 4 8 Alarm 17 17 Emergency
Output
distance: 2.2

Validator 6 Validator
Input
10 10 5 1 1 1 88 88 Alarm 11 11 Alarm 4 8 Emergency 17 17 Priority
Output
distance: 1.4

Solution language

Solution

Stub generator input