以下这段代码
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <complex>
const int N = 1e6 + 7;
const long double pi = 3.14159265358979323846;
std::vector <std::complex<long double>> FFT(std::vector <std::complex<long double>> a, int n) {
if(n == 1) return a;
std::complex <long double> Wn = {std::cos(2 * pi / n), std::sin(2 * pi / n)};
std::complex <long double> w = 1.0;
std::vector <std::complex <long double>> a0(n >> 1), a1(n >> 1);
for(int i = 0; i < (n >> 1); i++)
a0[i] = a[i << 1], a1[i] = a[(i << 1) | 1];
std::vector <std::complex<long double>> y0 = FFT(a0, n >> 1);
std::vector <std::complex<long double>> y1 = FFT(a1, n >> 1);
std::vector <std::complex<long double>> y(n);
for(int i = 0; i < (n >> 1); i++, w = w * Wn) {
y[i] = y0[i] + y1[i] * w;
y[i + (n >> 1)] = y0[i] - y1[i] * w;
}
return y;
}
int main() {
int n;
std::cin >> n;
int l = 1;
while(l < n) l <<= 1;
//std::cout << "l " << l << '\n';
std::vector <std::complex <long double>> a(n);
for(int i = 0; i < n; i++) {
int t;
std::cin >> t;
a[i] = (long double)t;
}
std::vector <std::complex<long double>> fa = FFT(a, l);
std::cout << fa[0].real() << "real";
printf("%f\n", fa[0].real());
for(int i = 0; i < n; i++) printf("%lf+%lfi ", fa[i].real(), fa[i].imag());
return 0;
}
输入 1 3
输出
3real0.000000
0.000000+0.000000i
就是说 cout
和 printf()
输出 a[0].real()
不同,为什么