Minor Setback
Time limit3sMemory limit1024 MB
Given N tuned frequencies, find the single major or minor key that fits all of them, then print each pitch's name in that key.
- Level
Medium4 of 10
- Topics
- Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Some Music Theory
Musical pitches are described by frequencies on a logarithmic scale. The frequency corresponds to the pitch named . Multiplying a pitch's frequency by produces the next higher pitch. Table 1 lists the pitches used in Western music and their frequencies.
Table 1: Frequencies and pitch names of various notes.
Doubling a pitch's frequency yields the same pitch one octave higher. Both and are . This rule generalizes: multiplying by a power of two yields another . Some pitches have multiple names, as shown in the table.
Input
The first line contains a single integer , the number of frequencies in the song. The next lines each contain a real number , one pitch frequency, with at most digits after the decimal point. You may assume the instrument was in tune, so each frequency approximates for some integer with absolute error at most .
Output
On the first line, print the name of the key the song was played in, such as G major or F# minor. Pitch names follow the format below. If the song fits none of the keys in Table 2, or if more than one key could fit, print cannot determine key.
If the key cannot be determined, print nothing else. Otherwise, print lines, each with one pitch name in input order. A pitch name is a letter from A to G, optionally followed by # for sharp or b for flat. A pitch can have several names, but for each key only the name listed in its allowed-pitches column is used. For example, in minor, print C# and not Db.