2020-2-3新生赛

数学方面的知识吧
问题 H: ###
时间限制: 1 Sec 内存限制: 128 MB
[提交] [状态]
题目描述
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y=yi. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x=xi.
For every rectangle that is formed by these lines, find its area, and print the total area modulo 109+7.
That is, for every quadruple (i,j,k,l) satisfying 1≤i<j≤n and 1≤k<l≤m, find the area of the rectangle formed by the lines x=xi, x=xj, y=yk and y=yl, and print the sum of these areas modulo 109+7.

Constraints
2≤n,m≤105
−109≤x1<…<xn≤109
−109≤y1<…<ym≤109
xi and yi are integers.
输入
Input is given from Standard Input in the following format:
n m
x1 x2 … xn
y1 y2 … ym
输出
Print the total area of the rectangles, modulo 109+7.
样例输入 Copy
3 3
1 3 4
1 3 6
样例输出 Copy
60
提示
The following figure illustrates this input:
**最开始以为这题是找规律…结果错了,然后看了别人的博客发现就是数学公式。
添加链接描述
**

#include<bits/stdc++.h>
using namespace std;
const int MOD = 1E9+7;//积累这个写法
long long int x[100005],y[100005];
int main()
{

 long long int n,m;
 scanf("%lld %lld",&n,&m);
 for(int i=1;i<=n;i++)
 {
     scanf("%lld",&x[i]);
 }
 for(int i=1;i<=m;i++)
 {
     scanf("%lld",&y[i]);
 }
 //公式推导((xi-xj)的和)*((yi-yj)的和)
 long long int s1=0,s2=0;
 for(int i=1;i<=n;i++)
 {
     s1+=(i-1)*x[i];
     s1-=(n-i)*x[i];
     s1%=MOD;
 }

//  sx=(sx+x[i]*(i-1))%MOD;
//  sx=(sx-x[i]*(n-i))%MOD;
 for(int i=1;i<=m;i++)
 {
     s2+=(i-1)*y[i];
     s2-=(m-i)*y[i];
      s2%=MOD;
 }
 long long int s=s1%MOD*s2%MOD;
 printf("%lld",s%MOD);
    return 0;
}


发布了32 篇原创文章 · 获赞 1 · 访问量 1349

猜你喜欢

转载自blog.csdn.net/QXK_Jack/article/details/104162587
今日推荐