一道ACM题目,看不懂

来源:百度知道 编辑:UC知道 时间:2024/06/02 14:13:51
1026 Major ScalesTimeLimit : 1 Second Memorylimit : 32 Megabyte

Totalsubmit : 37 Accepted : 20

In music, the range of audible frequencies is divided into octaves, where each octave spans frequencies within factor of 2 of one another. For example, the note called middle C corresponds to an audio frequency of 263 Hz. The octave below middle C spans the frequency range from 131.5 Hz to 263 Hz while the octave above middle C spans the range from 263 Hz to 526 Hz.

An octave contains 13 chromatic notes whose frequencies differ by a common ratio. The separation between two adjacent chromatic notes is called a half-step or semi-tone. Note that there are 12 semi-tones in an octave and therefore the frequency ratio represented by a semi-tone is 1.0593 (since 1.0593^12 = 2). A tone is two semi-tones.
While it might be convenient to use frequencies to describe musical notes, historical tradition demands that we name the notes of the chromatic scale, i

这道题目和乐理有关系. 题目大意是输入一串或多串半音符序列(每串用一行表示, 每个半音符间用空格隔开), 然后程序要判断每串音符可能采用了哪些调号, 再输出(每个调号间用空格隔开).

首先理解:

1) 半音符序列为: C C# D D# E F F# G G# A A# B C ....(每两个代号之间相差半音)
2) 大调音阶(major scale)的定义: 可以任何一个半音符开始(此半音符即称为此串音符的调号)的由8个半音符组成的任意排序的序列, 但这8个半音符是根据"全音-全音-半音-全音-全音-全音-半音"这个规律来挑选的. 即第一个半音符与第二个半音符之间相差全音(即两个半音), 第二音与第三音间也是相差全音, 第三音与第四音间相差半音, 如此类推......

所以, 程序应该先根据以上先定义出所有可能的大调音阶(major scale), 如:

C大调(the major scale in the key of C)由以下8个半音符组成:
C D E F G A B C
C#大调: C# D# F F# G# A# C C#
D大调: D E F# G A B C# D
......

题目所举例子的解释:
第一行: C C D F E G A A F G B, 去除重复的半音符后剩下C D E F G A B, 然后程序与所有的大调比较, 发现能全部包括这7个半音符的调号只有C, 所以输出"C"
第二行: A B C D E F G C#, 程序与所有的大调比较, 发现没有一个调号的大调能全部包括这8个半音符, 所以输出为空
第三行: C C D F E G A A F G, 去除重复的半音符后剩下C D E F G A, 然后程序与所有的大调比较, 发现能全部包括这6个半音符的调号有C和F, 所以输出"C F"
第四行: C C C C C, 去除重复的半音符后剩下C, 然后程序与所有的大调比较, 发现能包括这一个半音符的调号有C,C#,D#,F,G,G#,A#这7种, 所以输出&quo