CSU 1524: Tone Number of MIDI

来源:互联网 发布:数据中心数据备份系统 编辑:程序博客网 时间:2024/06/05 08:02

题目:

Description

Recently, we have made a little software called Query by Humming. One of the important thing is to transform the frequency of a sound to the tone number of MIDI. You can see the relations between them in the picture below:

                                        t = 12.0 * log2(f/440) + 69.0

Generally, we can transform the frequency of a sound to the tone of MIDI using the formula below:

Here f is the frequency of the sound and t is the tone of MIDI.
Then the integer nearest to t is the tone number. That is, the tone number is an integer x such that |x - t| is minimum. You can assume there is only one integer is nearest to t in this problem.

Input

The first line contains the number of test cases T (0 < T ≤ 200).
For each test case, there is only one line containing a real number f (82 < f < 1047) with at most 5 decimal places, giving the frequency of a sound.

Output

For each test case, output the tone number transformed.

Sample Input

5440.0123463.45678840.003859.99700.5364

Sample Output

6970808177


只有一个地方需要注意,int()这个函数,如果参数是负数,那么算出来的就和高斯函数不一样了,所以69只能放括号里面,不能放最外面。

代码:

#include<iostream>#include<math.h>using namespace std;int main(){int t;cin >> t;double f;while (t--){cin >> f;cout << int(log2(f / 440) * 12 + 69.5) << endl;}return 0;}

1 0
原创粉丝点击