1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)

湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训。

由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可。

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
const int N = 1000008, INF = 0x3F3F3F3F;
int sq[N];
int a[N], b[N];
struct data{
int num, cnt;
}a1[N], b1[N];
int t1, t2; int main(){
for(int i = 0; i < N; i++){
sq[i] = sqrt(i + 0.01);
}
int n, m;
while(~scanf("%d %d", &n, &m)){
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
int mx = 0;
int tp;
for(int i = 0; i < n; i++){
scanf("%d", &tp);
mx = max(mx, tp);
a[tp]++;
} for(int i = 0; i < m; i++){
scanf("%d", &tp);
mx = max(mx, tp);
b[tp]++;
} t1 = t2 = 0;
for(int i = 0; i <= mx; i++){
if(a[i]){
a1[t1].num = i;
a1[t1].cnt = a[i];
t1++;
}
if(b[i]){
b1[t2].num = i;
b1[t2].cnt = b[i];
t2++;
}
}
LL ans = 0;
for(int i = 0; i < t1; i++){
for(int j = 0; j < t2; j++){
ans += (LL)a1[i].cnt * (LL)b1[j].cnt * sq[abs(a1[i].num - b1[j].num)];
}
}
cout<<ans<<"\n"; } return 0;
}

  

上一篇:修改数据库用户名--CMD环境执行有效


下一篇:Fast Fourier Transform