Min-Max Scaling: Fair Fit, Fair Price
You run a tiny startup that matches shoppers to shoes using KNN. Each person is described by two features - foot length in centimeters and budget in dollars. Dollars swamp centimeters, so KNN can’t judge fairly. To restore balance, you decide to scale both features to the same range before comparing people.
You are asked to read some preexisting data and then scale new entries. Compute the minimum and maximum for each column using the preexisting data only, then transform every new row so that each column lies in the range [0,1]
:
If a column (either foot length or budget) in the preexisting data is flat (all values are equal), its scaled value is 0 for every new row.
The first line of the input contains a single integer n
representing how many rows of preexisting data you have. Each of the next n
lines contains two floating-point numbers: foot length in centimeters and budget in dollars.
The next line contains a single integer q
representing how many new rows you want to scale. Each of the next q
lines contains two floating-point numbers: foot length and budget - to be scaled using the min and max computed from the preexisting data.
The program should print q
lines. Each line should contain two floating-point numbers - the scaled foot length and the scaled budget for the corresponding new row.
Input | Output |
---|---|
3 | 0.25 0.25 |
2 | 0.5 0 |
4 | 0.1666666667 0.5 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB