http://www.cnblogs.com/skyivben/archive/2008/07/23/1248413.html
整理一下模板
hdu1402
sincos需要手写,因为hdu没有
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const double pi = acos(-1.0);
const int maxn = 1 << 18;
struct Complex {
double x, y;
Complex (double real = 0, double imag = 0) : x(real), y(imag) {}
double &real() {
return x;
}
double &imag() {
return y;
}
void print()
{
cout<<"real="<<x<<" imag=%.7lf\n"<<y<<endl;
}
}Pa[500000],Pb[500000],Pc[500000];
long long ans[500000],la,lb,N,A[500000],B[500000];
char a[500000],b[500000];
int t;
Complex operator+(const Complex &a, const Complex &b) {
return Complex(a.x + b.x, a.y + b.y);
}
Complex operator-(const Complex &a, const Complex &b) {
return Complex(a.x - b.x, a.y - b.y);
}
Complex operator*(const Complex &a, const Complex &b) {
return Complex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
inline void sincos(double theta,double &p0,double &p1)
{
p0=sin(theta);
p1=cos(theta);
}
void FFT(Complex P[], int n, int oper)
{
for (int i = 1, j = 0; i < n - 1; i++) {
for (int s = n; j ^= s >>= 1, ~j & s;);
if (i < j) {
swap(P[i], P[j]);
}
}
Complex unit_p0;
for (int d = 0; (1 << d) < n; d++) {
int m = 1 << d, m2 = m * 2;
double p0 = pi / m * oper;
sincos(p0, unit_p0.y, unit_p0.x);
for (int i = 0; i < n; i += m2) {
Complex unit = 1;
for (int j = 0; j < m; j++) {
Complex &P1 = P[i + j &#