結果

問題 No.1905 PURE PHRASE
ユーザー hitonanode
提出日時 2022-02-07 01:06:50
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,035 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 111,408 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-22 17:21:47
合計ジャッジ時間 3,293 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

// 想定別解
// exp(2 pi i f t) と内積をとって絶対値最大のものを出力する
#include <complex>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const vector<double> freqs{261.6, 294.3, 327.0, 348.8, 392.4, 436.0, 490.5};
const vector<string> names{"C4", "D4", "E4", "F4", "G4", "A4", "B4"};

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<double> A(N);
    for (auto &x : A) cin >> x;

    const double PI = acos(-1);
    double high = -1;
    int arghi = -1;

    for (int d = 0; d < int(freqs.size()); ++d) {
        complex<double> v = 0;
        for (int frame = 0; frame < N; ++frame) {
            double hanning = 0.5 - 0.5 * cos(PI * 2 * frame / N);
            v += exp(complex<double>(0.0, PI * 2 * frame / N * freqs[d])) * A[frame] * hanning;
        }
        if (high < abs(v)) {
            high = abs(v);
            arghi = d;
        }
    }
    cout << names.at(arghi) << '\n';
}
0