Smoothie Seer: Three Lights, Three Neighbors
In the Oracle of Smoothies, fruit is judged as “eat” or “wait.” The oracle listens to two knobs: sweetness
and firmness
(which are numbers), and watches the skin color lights (represented as text). New colors show up all the time; the oracle isn’t surprised.
You are asked to learn from an initial notebook of fruit, then decide on new fruit using the 3 nearest neighbors. Standardize sweetness and firmness using statistics from the initial notebook only (subtract the mean and divide by the standard deviation). If a column is flat, its scaled value is 0. Build a color vector from the given color vocabulary using one-hot encoding - unknown colors become all zeros.

Concatenate numeric and color parts, measure Euclidean distance, let the three nearest vote, and if the votes tie, print the alphabetically smallest label.
The first line of the input contains a single integer v
representing the number of known colors. The second line contains v
space-separated color tokens. The next line contains a single integer n
representing how many fruit entries are in the initial notebook. Each of the next n
lines contains two floating-point numbers and a label with no spaces - sweetness firmness color label
. The next line contains a single integer q
. Each of the next q
lines contains sweetness firmness color
for fruit to classify using the scaling statistics computed from the initial notebook.
The program should print q
lines. Each line should contain the predicted label for the corresponding fruit.
Input | Output |
---|---|
3 | eat |
4 | eat |
3 | eat |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB