# 2016长城信息杯中国大学生程序设计竞赛中南邀请赛 xtu 1250 Super Fast Fourier Transform

903人阅读 评论(0)

Bobo has two sequences of integers{a1,a2,,an}and{b1,b2,,bm}. He would like to find

i=1nj=1m|aibj|.

Note thatxdenotes the maximum integer does not exceedx, and|x|denotes the absolute value ofx.

## Input

The input contains at most30sets. For each set:

The first line contains2integersn,m(1n,m105).

The second line containsnintegersa1,a2,,an.

The thrid line containsmintegersb1,b2,,bm.

(ai,bi0,a1+a2++an,b1+b2+,bm106)

## Output

For each set, an integer denotes the sum.

## Sample Input

1 2
1
2 3
2 3
1 2
3 4 5

## Sample Output

2

#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string.h>
using namespace std;
int a[100005],b[100005],suma[1000005],sumb[1000005];
int main()
{
int la,lb,t,n,m;
long long ans;
while(~scanf("%d %d",&n,&m))
{
memset(suma,0,sizeof suma);
memset(sumb,0,sizeof sumb);
la=lb=0;
for(int i=0;i<n;i++)
{
scanf("%d",&t);
if(suma[t]==0)
a[la++]=t;
suma[t]++;
}
for(int i=0;i<m;i++)
{
scanf("%d",&t);
if(sumb[t]==0)
b[lb++]=t;
sumb[t]++;
}
ans=0;
for(int i=0;i<la;i++)
for(int j=0;j<lb;j++)
{
ans+=(long long)suma[a[i]]*sumb[b[j]]*(long long)(sqrt(abs(a[i]-b[j])));
}
printf("%lld\n",ans);
}
return 0;
}

0
0

个人资料
• 访问：64767次
• 积分：2246
• 等级：
• 排名：第19710名
• 原创：160篇
• 转载：30篇
• 译文：0篇
• 评论：1条
文章分类
最新评论