← 返回 apple 的题目列表Highway Toll Fee From Checkpoint Logs
类型:online_judge
Problem: Compute Highway Toll From Checkpoint Logs
A highway has multiple checkpoints. Each time a vehicle passes a checkpoint, a log record is generated containing:
car_id: license plate / vehicle id (string)
checkpoint: checkpoint name (string)
t: timestamp (integer, consistent unit)
A log record is a triplet (car_id, checkpoint, t), e.g. ('C1', 'A', 1).
The system provides:
get_coordinates(checkpoint_name) -> (x, y): returns 2D coordinates for a checkpoint.
Pricing rule
Charge each continuous highway trip as:
Base fee: $2
Distance fee: $0.1 * distance
where distance is the sum of straight-line (Euclidean) distances between consecutive checkpoints within that trip:
dist((x1,y1),(x2,y2)) = sqrt((x1-x2)^2 + (y1-y2)^2)
Trip segmentation
For the same vehicle, connect logs in time order.
If the time gap between two consecutive logs is > 1, the vehicle is considered off the highway:
the previous trip ends at the earlier log
a new trip starts at the later log
Task
Given a list of log records, output the total toll for each car (sum over all its trips).
Requirements:
A car may have multiple trips
Logs may contain multiple cars
Compute totals per car
Suggested I/O
Input:
First line: integer M (# of logs)
Next M lines: car_id checkpoint t
Output:
Multiple lines: car_id total_fee (any order or sorted by car_id)
Fees may be printed with 2 decimals
Constraints (suggested)
1 <= M <= 2*10^5
Coordinate absolute value <= 1e6
t is a non-negative integer
Example
Assume:
A(0,0), B(3,4), C(6,8)
logs:
('C1','A',1)
('C1','B',2)
('C1','C',3)
Distance is 5 + 5 = 10, fee is 2 + 0.1*10 = 3.0.
Example
Input
3
C1 A 1
C1 B 2
C1 C 3
Output
C1 3.00