Listening to music is a good way to take one’s mind off the monotony of typing out solutionafter correct solution.However, it can be very annoying to start listening to a tune and then for time to run out early,cutting the listening short. How much more satisfying it would be if you could choose tunes tofit the time available!With this in mind, you have found a way to code musical scores into simple lists of numbersrepresenting the length of the notes in each tune as follows:

Given such a list of numbers, calculate the length of the tune in notes.
Input•
One line containing the integer N (1 ≤ N ≤ 2000), the number of values in the tune.• one line containing N integers each representing the length of a value using the codesabove.
Output
Output the length of the tune, as a real number of notes. The output must be accurate to anabsolute or relative error of at most 10−6.
Sample Input 1 Sample Output 1
4 5
1 1 1 0
Sample Input 2 Sample Output 2
10
1 2 2 2 1 4 4 8 8 16 4.3125
题目:每个数字对应一个长度,给也一列数字,计算音符中音调的长度。
(样例有个坑,输出结果要保留6位数,虽然没有保留也能过几个,但是会卡在text 6那过不去)
#include <iostream>
#include <cstdio>
using namespace std;
int n0=0,n1=0,n2=0,n4=0,n8=0,n16=0;
float res=0;
int main()
{
int n;
int temp;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>temp;
if(temp==0) n0++; //计算各个数字的个数
else if(temp==1) n1++;
else if(temp==2) n2++;
else if(temp==4) n4++;
else if(temp==8) n8++;
else if(temp==16) n16++;
}
res+=n0*2+n1+n2*0.5+n4*0.25+n8*0.125+n16*0.0625; //乘以对应长度相加
// cout<<res<<endl;
printf("%f\n",res); //float型默认保留小数点后六位
return 0;
}
本文介绍了一种通过将音乐分数转换为数字列表来计算音乐长度的方法。该算法接收一系列数字作为输入,每个数字代表不同的音符长度,然后计算并输出整个曲目的总长度。
364

被折叠的 条评论
为什么被折叠?



