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

http://www.dengwenhuo.cn/?id=196

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

i=1nj=1m|aibj|.

Note that x denotes the maximum integer does not exceed x , and |x| denotes the absolute value of x .

Input

The input contains at most 30 sets. For each set:

The first line contains 2 integers n,m ( 1n,m105 ).

The second line contains n integers a1,a2,,an .

The thrid line contains m integers b1,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

贡献了十几波wa。。。。g++和g++11 编译器的问题?g++交了十几次 换个g++11就过了 omg

有10^5个数 然后所有数的和小于10^6次方 一眼感觉下去会有很多重复的数 去一下重就好了。。

#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值