2019 牛客多校第一场 B Integration
题目链接:https://ac.nowcoder.com/acm/contest/881/B
题目大意
给定 n 个不同的正整数 ai,求$\frac{1}{\pi}\int_{0}^{\infty} \frac{1}{\prod\limits_{i=1}^{n}(a_i^2+x^2)}dx$模 109 + 7。(可以证明这个积分一定是有理数)
分析
$$\begin{align*}
&令c_i = \frac{1}{\prod_{j \ne i} (a_j^2 - a_i^2)} \\
&则\frac{1}{\prod\limits_{i=1}^{n}(a_i^2+x^2)} = \sum\limits_{i=1}^{n} \frac{c_i}{a_i^2+x^2} \\
&而\int_{0}^{\infty} \frac{c_i}{a_i^2+x^2}dx = \frac{c_i}{2a_i}\pi \\
&于是\frac{1}{\pi}\int_{0}^{\infty} \frac{1}{\prod\limits_{i=1}^{n}(a_i^2+x^2)}dx = \sum\limits_{i=1}^{n} \frac{c_i}{2a_i}
\end{align*}$$
补:关于裂项,也就是$c_i$怎得得出来,以两项为例。
以 $x$ 代替 $x^2$,$-y_i$ 代替 $a_i^2$。
则$\frac{1}{(x - y_1)(x - y_2)} = \frac{1}{y_1 - y_2} * (\frac{1}{x - y_1} - \frac{1}{x - y_2}) = \frac{1}{y_1 - y_2} * \frac{1}{x - y_1} + \frac{1}{y_2 - y_1} * \frac{1}{x - y_2}$。
三项以至于更多项同理,可以找出规律。
熟练以后建议当作公式来记住。
你所以为的顿悟,常常只是别人的基本功。
代码如下
#include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // ?? x ?????? c
#define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper); #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T>
ostream &operator<<(ostream &out, vector<T> &v) {
Rep(i, v.size()) out << v[i] << " \n"[i == v.size()];
return out;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} template<class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
} inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
} //min <= aim <= max
template<typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
return min <= aim && aim <= max;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< int, PII > PIPII;
typedef pair< string, int > PSI;
typedef pair< int, PSI > PIPSI;
typedef set< int > SI;
typedef set< PII > SPII;
typedef vector< int > VI;
typedef vector< double > VD;
typedef vector< VI > VVI;
typedef vector< SI > VSI;
typedef vector< PII > VPII;
typedef map< int, int > MII;
typedef map< int, string > MIS;
typedef map< int, PII > MIPII;
typedef map< PII, int > MPIII;
typedef map< string, int > MSI;
typedef map< string, string > MSS;
typedef map< PII, string > MPIIS;
typedef map< PII, PII > MPIIPII;
typedef multimap< int, int > MMII;
typedef multimap< string, int > MMSI;
//typedef unordered_map< int, int > uMII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 1e3 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; //ax + by = gcd(a, b) = d
// 扩展欧几里德算法
/**
* a*x + b*y = 1
* 如果ab互质,有解
* x就是a关于b的逆元
* y就是b关于a的逆元
*
* 证明:
* a*x % b + b*y % b = 1 % b
* a*x % b = 1 % b
* a*x = 1 (mod b)
*/
inline void ex_gcd(LL a, LL b, LL &x, LL &y, LL &d){
if (!b) {d = a, x = , y = ;}
else{
ex_gcd(b, a % b, y, x, d);
y -= x * (a / b);
}
} // 求a关于p的逆元,如果不存在,返回-1
// a与p互质,逆元才存在
inline LL inv_mod(LL a, LL p = mod){
LL d, x, y;
ex_gcd(a, p, x, y, d);
return d == ? (x % p + p) % p : -;
} LL add_mod(LL a, LL b) {
return (a + b) % mod;
} LL mul_mod(LL a, LL b) {
return (a * b) % mod;
} LL sub_mod(LL a, LL b) {
return (a - b + mod) % mod;
} LL n, a[maxN], c[maxN], ans; int main(){
//freopen("MyOutput.txt","w",stdout);
//freopen("input.txt","r",stdin);
//INIT();
while(~scanf("%lld", &n)) {
ans = ;
For(i, , n) scanf("%lld", &a[i]); For(i, , n) {
c[i] = ;
For(j, , n) {
if(i == j) continue;
c[i] = mul_mod(c[i], sub_mod(mul_mod(a[j], a[j]), mul_mod(a[i], a[i])));
}
ans = add_mod(ans, inv_mod(mul_mod(a[i], * c[i])));
} printf("%lld\n", ans);
}
return ;
}
2019 牛客多校第一场 B Integration的更多相关文章
- 2019牛客多校第一场 I  Points Division(动态规划+线段树)
		
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
 - 2019牛客多校第一场E ABBA(DP)题解
		
链接:https://ac.nowcoder.com/acm/contest/881/E 来源:牛客网 ABBA 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语 ...
 - 2019牛客多校第一场A-Equivalent Prefixes
		
Equivalent Prefixes 传送门 解题思路 先用单调栈求出两个序列中每一个数左边第一个小于自己的数的下标, 存入a[], b[].然后按照1~n的顺序循环,比较 a[i]和b[i]是否相 ...
 - 2019牛客多校第一场 A.Equivalent Prefixes
		
题目描述 Two arrays u and v each with m distinct elements are called equivalent if and only if RMQ(u,l,r ...
 - 2019 牛客多校第一场 D Parity of Tuples
		
题目链接:https://ac.nowcoder.com/acm/contest/881/D 看此博客之前请先参阅吕凯飞的论文<集合幂级数的性质与应用及其快速算法>,论文中很多符号会被本文 ...
 - 2019牛客多校第一场 E-ABBA(dp)
		
ABBA 题目传送门 解题思路 用dp[i][j]来表示前i+j个字符中,有i个A和j个B的合法情况个数.我们可以让前n个A作为AB的A,因为如果我们用后面的A作为AB的A,我们一定也可以让前面的A对 ...
 - 【2019牛客多校第一场】XOR
		
题意: 给你一个集合A,里边有n个正整数,对于所有A的.满足集合内元素异或和为0的子集S,问你∑|S| n<=1e5,元素<=1e18 首先可以转化问题,不求∑|S|,而是求每个元素属于子 ...
 - 2019牛客多校第一场E ABBA 贪心 + DP
		
题意:问有多少个有(n + m)个A和(n + m)个B的字符串可以凑出n个AB和m个BA. 思路:首先贪心的发现,如果从前往后扫,遇到了一个A,优先把它看成AB的A,B同理.这个贪心策略用邻项交换很 ...
 - 2019 牛客多校第一场 F Random Point in Triangle
		
题目链接:https://ac.nowcoder.com/acm/contest/881/F 题目大意 给定二维平面上 3 个整数表示的点 A,B,C,在三角形 ABC 内随机选一点 P,求期望$E ...
 
随机推荐
- android&iOS设计分辨率
			
--- iPhone --- iPhone SE 1136 * 640 2.0875 iPhone 6 1334 * 750 1.778666666666667 iPhone X 2436 * 112 ...
 - NVIDIA Jetson™ TX1
			
NVIDIA® Jetson TX1 是一台模块式计算机,代表了视觉计算领域近20年的研发成就,其尺寸仅有信用卡大小.Jetson TX1 基于崭新 NVIDIA Maxwell™ 架构,配有256个 ...
 - Django 高级配置
			
目录 Django 信号 信号系统三要素: 信号的分类: Django 内置信号: 具体 Django 信号内容 定义信号 发送信号 接收信号 信号接收器 防止重复信号 Django 内置信号操作步骤 ...
 - hdu1231  最长连续子序列和
			
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1231 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, N ...
 - Vue:对象更改检测注意事项
			
还是由于 JavaScript 的限制,Vue 不能检测对象属性的添加或删除: var vm = new Vue({ data: { a: 1 } }) // `vm.a` 现在是响应式的 vm.b ...
 - HTML基础 块级元素和内联元素
			
大多数 HTML 元素被定义为块级元素或内联元素. 块级元素包括:body from select textarea h1-h6 html table button hr p ol ...
 - 线程池(ThreadPool)创建
			
线程池创建方式jdk1.5 Java通过Executors(jdk1.5并发包)提供四种线程池,分别为: newCachedThreadPool创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活 ...
 - Fiddler的详细介绍
			
Fiddler的详细介绍 一.Fiddler与其他抓包工具的区别 1.Firebug虽然可以抓包,但是对于分析http请求的详细信息,不够强大.模拟http请求的功能也不够,且firebug常常是需要 ...
 - Erlang/Elixir精选-第4期(20191223)
			
精选文章 A digital symphony - The architecture of API Fortress. 使用Actor模型来支持基于微服务的大规模分布式软件架构.用实例解释了Actor ...
 - logstash配置文件详解
			
logstash pipeline 包含两个必须的元素:input和output,和一个可选元素:filter. 从input读取事件源,(经过filter解析和处理之后),从output输出到目标 ...