题目链接: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 ;
}

最新文章

  1. Redis简单案例(四) Session的管理
  2. jquery----常用的函数
  3. DevExpress DXperience 的本地化(汉化)方法
  4. Runtime -----那些被忽略的技能
  5. IOS枚举使用
  6. MongoDB(2):入门
  7. URAL1900 Brainwashing Device(dp)
  8. EhCache 分布式缓存/缓存集群
  9. asp.net 网站和asp.net Web 应用程序的一处不同
  10. ORM增删改查询例题
  11. POJ 2823 Sliding Window​ (模板题)【单调队列】
  12. ZMQ示例:使用 curve 进行加密通信
  13. google的Python风格规范
  14. [源码]Delphi源码免杀之函数动态调用 实现免杀的下载者
  15. odoo开发笔记 -- odoo web机制浅析
  16. 第二篇:呈现内容_第三节:CompositeControl呈现
  17. ZooKeeper-3.4.10分布式安装指南
  18. 配置idea解决乱码
  19. [POI2007]立方体大作战tet
  20. 检测 iOS 系统网络权限被关闭

热门文章

  1. RabbitMQ ——与Spring集成及exchange的direct、topic方式实现和简单队列实现
  2. elasticsearch 基础 —— _mget取回多个文档及_bulk批量操作
  3. Redis在windows下的环境搭建
  4. 使用Unsafe来实现自定义锁
  5. CentOS 6.5之SSH 免密码登录
  6. mongodb 索引分类
  7. Center os vi
  8. opencl(九)----标量、向量数据类型
  9. 插入排序-&gt;希尔排序
  10. springboot实战(汪云飞)学习-1-1