Improvisation
Time limit1sMemory limit128 MB
Given a chord progression and a melody with pauses, remap each played note to the nearest note in the current chord's scale, advancing the chord every fourth position.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation, Array, String
- Solved
- No attempts yet
Problem
Chris always dreamed of playing jazz. He has grown up but still cannot play a single instrument, so instead he wants to build a new kind of improvisation engine. His program, Improvisation, takes an improvisation that fits one chord progression and rewrites it so that it fits a different chord progression. Your task is to implement that algorithm.
A few definitions are needed first.
Notes. There are 12 notes, arranged in a fixed classical order:
C, C#(D♭), D, D#(E♭), E, F, F#(G♭), G, G#(A♭), A, A#(B♭), B
The order is cyclic: B is followed by C again. Each of the five notes written with a sharp (#) can also be written with a flat (♭).
Pause. A pause is written as _.
Chords. Every chord has a mode and a prime. The prime is a single note. There are six modes: maj7, min7, dim, 7, 7♭9, and 7#9. Each mode defines a scale: a set of note offsets relative to the prime in the classical order. For example, if the prime is D and , then the fitting notes are . The scales are:
A chord is written as its prime and mode joined into one word (for example, Cmaj7). The fitting notes of Cmaj7 are .
Improvisation. An improvisation is a finite sequence of notes and pauses.
Nearest fitting note. For a note and a chord , the nearest note that fits is the first element of the sequence
that fits , where is the note right after in the classical order and is the note right before it.
The algorithm takes a chord progression of length and an improvisation of length , and produces a new improvisation :
1 J := sequence of length n containing only pauses
2 p := 1
3 for i := 1 to n do begin
4 if I[i] <> pause then begin
5 J[i] := nearest note to I[i] which fits to P[p]
6 if i mod 4 = 0 then begin
7 p := p + 1
8 if p > m then p := 1
9 end
10 end
11 end
Read a chord progression and an improvisation, run the algorithm, and print the resulting improvisation .
Input
The first line contains one integer (). The second line contains chords separated by single spaces. The third line contains one integer (). The fourth line contains notes and/or pauses separated by single spaces, forming the improvisation.
In the input a sharp is written as # and a flat as the lowercase letter b: for example G♭ is written Gb, and the modes 7♭9 and 7#9 are written 7b9 and 7#9. A pause is _.
Output
Print one line with notes and/or pauses separated by single spaces: the resulting improvisation .
When a note has two spellings (a sharp note), print it using the spelling implied by the chord that produced it on line 5 of the algorithm. If that chord's prime is written with a flat, use the flat spelling; otherwise use the sharp spelling. As in the input, a sharp is # and a flat is b.