查看單個文章
舊 2018-03-09, 07:44 PM   #4 (permalink)
alanniok 帥哥
註冊會員
榮譽勳章

勳章總數0
UID - 369540
在線等級: 級別:3 | 在線時長:31小時 | 升級還需:1小時級別:3 | 在線時長:31小時 | 升級還需:1小時級別:3 | 在線時長:31小時 | 升級還需:1小時
註冊日期: 2015-06-21
文章: 59
精華: 0
現金: 91 金幣
資產: 91 金幣
預設

這是我後還寫的版本,感覺是可以用,不過方法比較像是暴力解法,之後要用到大量比對的時候猜想可能速度會太慢因此才來問看看有沒有什麼特別的演算法之類。
-------------------------------------------
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
int song[] = {1, 3, 5, 5, 7, 9, 11, 9, 7};// Put the real song fftw result here
int num;
int *a;// used to store fftw of recorded melody

cout << "Enter a number:";
cin >> num;

a = new int[num];

cout << "Please Enter the Number List:";
for(int i =0; i < num; i++)
{
cin >> a[i];
}

int x = a[0];
int yn = 0;
int r[num];
int temp = 0;
for(int i =0; i < num; i++)
{
r[i] = a[i] - x;
}
for(int i =0; i <= sizeof(song)/sizeof(int) - num; i++)
{
for(yn = 0; yn < num; yn++)
{
temp = song[i + yn] - song[i] - r[yn];
if( temp > 1 || temp < -1 )//誤差半音以內沒關係
break;
}
if(yn == num)
break;
}
if(yn == num)
cout << "yes";
else
cout << "no";
return 0;
}

此帖於 2018-03-09 08:13 PM 被 alanniok 編輯.
alanniok 目前離線  
送花文章: 75, 收花文章: 17 篇, 收花: 22 次
回覆時引用此帖