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;
}

  

转载于:https://www.cnblogs.com/IMGavin/p/6036210.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值