前言
- zxy大佬给我讲了讲,冲一波吧。
- 参考博客:【zxy大佬给我讲了一个模板题】
题目
- 题意:y=-1,0,1这条直线上分别有一些点,三条直线上各取一个点,在一条直线上的组合有多少。
- x维为整数,在
[
−
3
e
4
,
3
e
4
]
[-3e4,3e4]
[−3e4,3e4]范围内。
- 题解:
- 只看-1,1上的点,然后先增加3e4再多项式乘一下,得到答案(懒得叙述了emm)
- 代码:
#include <bits/stdc++.h>
#define dbg(x) cout << #x << "===" << x << endl
const int N = (1 << 17) + 5;
using namespace std;
int n, m, k;
int a[N], b[N], c[N];
const double PI = acos(-1.0);
struct Complex {
double x, y;
Complex(double _x = 0.0, double _y = 0.0) { x = _x, y = _y; }
Complex operator-(const Complex &b) const {
return Complex(x - b.x, y - b.y);
}
Complex operator+(const Complex &b) const {
return Complex(x + b.x, y + b.y);
}
Complex operator*(const Complex &b) const {
return Complex(x * b.x - y * b.y, x * b.y + y * b.x);
}
};
void change(Complex y[], int len) {
int i, j, k;
for (i = 1, j = len / 2; i < len - 1; i++) {
if (i < j) swap(y[i], y[j]);
k = len / 2;
while (j >= k) {
j -= k, k /= 2;
}
if (j < k) j += k;
}
}
void fft(Complex y[], int len, int on) {
change(y, len);
for (int h = 2; h <= len; h <<= 1) {
Complex wn(cos(-on * 2 * PI / h), sin(-on * 2 * PI / h));
for (int j = 0; j < len; j += h) {
Complex w(1, 0);
for (int k = j; k < j + h / 2; k++) {
Complex u = y[k];
Complex t = w * y[k + h / 2];
y[k] = u + t;
y[k + h / 2] = u - t;
w = w * wn;
}
}
}
if (on == -1)
for (int i = 0; i < len; i++) y[i].x /= len;
}
Complex x1[N], x2[N];
int va[N], vb[N], vc[N];
int len = (1 << 17);
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], a[i] += 3e4, va[a[i]] = 1;
cin >> m;
for (int i = 1; i <= m; i++) cin >> b[i], b[i] += 3e4, vb[b[i]] = 1;
cin >> k;
for (int i = 1; i <= k; i++) cin >> c[i], c[i] += 3e4, vc[c[i]] = 1;
for (int i = 0; i < len; i++) {
x1[i] = Complex(va[i], 0);
}
for (int i = 0; i < len; i++) {
x2[i] = Complex(vc[i], 0);
}
fft(x1, len, 1);
fft(x2, len, 1);
for (int i = 0; i < len; i++) x1[i] = x1[i] * x2[i];
fft(x1, len, -1);
int ans = 0;
for (int i = 0; i < N; i++) {
if (i % 2 == 1) continue;
if (vb[i / 2]) ans += int(x1[i].x + 0.5);
}
cout << ans << endl;
return 0;
}