Fuel Fairness: Scale, Then Neighbor
A road-trip planner estimates fuel use from two features: speed
(in km/h) and drive time
(in minutes). Time numbers dwarf speed, so KNN won’t judge fairly unless both features are scaled to the same range. The planner decides to first apply min–max scaling and then use KNN regression to predict fuel use.
You are asked to read some preexisting data, compute per-column min and max from it only, and use those to scale both the preexisting rows and each new row using the min-max scaling. If a column in the preexisting data is flat (all values equal), its scaled value is 0 for every row. After scaling, classify by KNN regression with Euclidean distance: for each new row, find the k nearest preexisting rows and print the average of their fuel targets.
The first line of the input contains two integers n k
representing how many rows of preexisting data there are, and the number of neighbors. Each of the next n
lines contains two floating-point numbers - speed and drive time, followed by a floating-point target for fuel used in liters.
The next line contains a single integer q
representing how many new rows to predict. Each of the next q
lines contains two floating-point numbers (speed and drive time) - to be scaled using the min and max computed from the preexisting data.
The program should print q
lines, each with a single floating-point number - the predicted fuel use for the corresponding new row.
Input | Output |
---|---|
4 2 | 7.5 |
6 3 | 7 |
3 2 | 6.5 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB