2020河南省ccpc省赛太阳轰炸

2020河南省ccpc省赛太阳轰炸

2020河南省ccpc省赛太阳轰炸

#include<bits/stdc++.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;


const int maxn = 5e6+5;
const int mod = 1e9 + 7;
typedef long long ll;
int n,m,k;
ll r1,r2,r,a,h;
int pm[maxn],pni[maxn];
int jc[maxn],inv[maxn];
ll p,q,p2,q2;
ll qmi(ll a,ll k,ll mod){
	ll res = 1;
	while(k){
		if(k & 1) res = 1ll*res * a % mod;
		a = 1ll*a * a % mod;
		k >>= 1; 
	}
	return res;
}
void solve(){
	cin >> n >> r1 >> r2 >> r >> a >> h;
	ll t = (h + a - 1) / a;
	if(t > n){
    	cout << 0 << endl;
    	return;
	}
	if(r1 + r >= r2){
    	cout << 1 << endl;
    	return;
	}
	//预处理阶乘 
	jc[0] = 1;
	for(int i = 1 ; i <= n ; ++i ){
		jc[i] = 1ll*jc[i - 1] * i % mod;
	}
	//预处理阶乘的逆元 
	inv[n] = qmi(jc[n],mod - 2,mod);
	for(int i = n - 1 ; i >= 0 ; --i ){
		inv[i] = 1ll*inv[i + 1] * (i + 1) % mod;
	}
	p = (r1 + r) * (r1 + r) % mod;
	p2 = (r2 * r2 - (r1 + r) * (r1 + r))% mod;
	q = r2 * r2 % mod;
	//预处理命中概率的前缀积,和未命中概率的前缀积 
	//预处理分母的逆元 
	q = qmi(q,mod - 2,mod);
	pm[0] = pni[0] = 1;
	for(int i = 1; i <= n ; ++i ){
		pm[i] = 1ll*pm[i - 1] * p % mod * q % mod;
		pni[i] = 1ll*pni[i - 1] * p2 % mod * q % mod;
	}
	ll ans = 0;
	// 答案为Σ(t <= i <= n)C(n,i)*p(命中率)^i * (1 - p)(未命中率)^(n-1); 
	for(int i = t ; i <= n ; ++i ){
		ans = (ans + 1ll*jc[n] % mod * inv[i] % mod * inv[n - i] % mod * pm[i] % mod * pni[n - i] % mod) % mod;
	}
	cout << ans << endl;
}

main(){
	IOS;
	solve();
}

 

上一篇:2019年 五月份ccpc湘潭、icpc西安南昌邀请赛总结


下一篇:2018 CCPC 网络赛