灵异事件
  • 板块学术版
  • 楼主Sukilin
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/1/18 21:53
  • 上次更新2025/1/18 22:04:17
查看原帖
灵异事件
959201
Sukilin楼主2025/1/18 21:53

以下这段代码

#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

就是说 coutprintf() 输出 a[0].real() 不同,为什么

2025/1/18 21:53
加载中...