链接:https://ac.nowcoder.com/acm/contest/881/B
来源:牛客网

Bobo knows that 

Given n distinct positive integers a1,a2,…,anfind the value of

It can be proved that the value is a rational number
Print the result as 

输入描述:

The input consists of several test cases and is terminated by end-of-file.The first line of each test case contains an integer n.
The second line contains n integers a1,a2,…,an* 1≤n≤1e3
* 1≤ai≤1e9
* {a1,a2,…,an} are distinct.
* The sum of n*n does not exceed 1e7.

输出描述:

For each test case, print an integer which denotes the result.

示例1

输入

复制

1
1
1
2
2
1 2

输出

复制

500000004
250000002
83333334

思路,裂项相消+积分公式

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<list>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll a[1005];
int n;
ll ksm(ll a,ll b){ll s=1;while(b){if(b&1)s = s * a % mod;a= a *a %mod;b>>=1;}return s%mod;
}
int main(){while(~scanf("%d",&n)){for(int i=1;i<=n;i++){scanf("%d",&a[i]);}ll ans=0;for(int i=1;i<=n;i++){ll temp=1;for(int j=1;j<=n;j++){if(j!=i){temp*=(a[j]*a[j]-a[i]*a[i])%mod;temp=(temp%mod+mod)%mod;}}ans+=ksm(temp*(a[i]<<1)%mod,mod-2)%mod;ans%=mod; } printf("%lld\n",ans);}return 0;
} 

2019牛客暑期多校训练营(第一场) Integration(定积分)相关推荐

  1. 2019牛客暑期多校训练营(第一场场)_I题Points Division(线段树+DP维护区间最大值)

    题目链接: https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点的坐标为(xi,yi),有两个权值ai,bi. 现在要你将它分成A,B两部分, ...

  2. 2019牛客暑期多校训练营(第三场)H.Magic Line

    2019牛客暑期多校训练营(第三场)H.Magic Line 题目链接 题目描述 There are always some problems that seem simple but is diff ...

  3. 2019牛客暑期多校训练营(第五场)C generator 2 (BSGS)

    2019牛客暑期多校训练营(第五场)C generator 2 思路 x0=x0x_0 = x_0x0​=x0​ x1=a∗x0∗bx_1 = a * x_0 * bx1​=a∗x0​∗b x2=a∗ ...

  4. 2019牛客暑期多校训练营(第四场)----E- triples II

    首先发出题目链接: 链接:https://ac.nowcoder.com/acm/contest/884/E 来源:牛客网 涉及:位运算,容斥定义,dp 点击这里回到2019牛客暑期多校训练营解题-目 ...

  5. 2019牛客暑期多校训练营(第一场)

    传送门 参考资料: [1]:官方题解(提取码:t050 ) [2]:标程(提取码:rvxr ) [3]:牛客题解汇总 A.Equivalent Prefixes(单调栈) •题意 定义两个数组 u,v ...

  6. 【2019牛客暑期多校训练营(第一场) - A】Equivalent Prefixes(单调栈,tricks)

    题干: 链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Two arrays u and v each with m distinct elem ...

  7. 2019牛客暑期多校训练营(第一场)E-ABBA(dp)

    链接:https://ac.nowcoder.com/acm/contest/881/E 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  8. 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...

  9. 【2019牛客暑期多校训练营(第一场) - H】XOR(线性基,期望的线性性)

    题干: 链接:https://ac.nowcoder.com/acm/contest/881/H 来源:牛客网 Bobo has a set A of n integers a1,a2,-,ana1, ...

最新文章

  1. 每个程序员都应该收藏的算法复杂度速查表
  2. python 打开网页、封装自己的浏览器、制作浏览器、打开麦克风和摄像头、忽略ssl证书错误、置顶、无边框
  3. 大话设计模式之装饰模式
  4. bash: _upvars: `-a2‘: invalid number specifier bash: /dev/null: 权限不够 bas
  5. 关于Modernizr的使用
  6. ASPNET Core 2.x中的Kestrel服务器
  7. 东北农业大计算机排名,黑龙江高校排名更新,东北林大排名第3,东油排名第8...
  8. linux 小度 驱动_Linux硬链接和软链接
  9. [翻译] InstagramPhotoPicker
  10. 强化学习 RL - DQN - 智能体Agent
  11. iOS中Navigation中添加自定义Button等UIView
  12. linux 内存性能评估,linux的内存性能评估
  13. 基于集成学习模型的估价预测(量化投资)
  14. android软件音量控制
  15. 第一章 计算流体力学动力学基础知识
  16. 免费图书的检索和获取途径
  17. 远程服务器 检索{00024500-0000-0000-C000-000000000046}组件失败 80080005 服务器运行失败 解决方案
  18. python 自动解4399数独游戏
  19. Kaggle Top1% 是如何炼成的!
  20. Mac电脑Finder侧边栏不显示iCloud云盘怎么办?

热门文章

  1. [概念]深度学习5种标准化层BN、GN、LN、IN、SN + 谷歌提出新的标准化层:FRN
  2. 原生JavaScript抒写——贪吃蛇小游戏
  3. FPGA零基础学习:IIC协议驱动设计
  4. 响铃:从艾媒季度监测报告,看混战后在线音乐的稳态格局
  5. 全国计算机王牌专业的一本大学,最值得报考的22所“普通一本”大学,王牌专业比985大学还牛!...
  6. 基于模糊+pid控制的空调控制系统 matlab simulink仿真
  7. 用Python的Pandas绘制股票唐奇安通道!
  8. 计算机中常见乱码原因及分析
  9. 冰球项目日志4-yjw
  10. 连接众宽 服务器无响应,为什么移动网络无法访问部分网站,怎么样才能解决呢? - 爱加速...