等级之题N2(8.3)
题目传送门
思路
很明显的推公式:
首先根据题目很容易就可以得出这个公式
然后化简为
代码
#include<cmath>
#include<cstdio>
#include<iostream>
const double pi = acos(-1.0);
using namespace std;
int main(){
double s;
cin>>s;
printf("%.3lf\n", 2*sqrt(s/pi));
return 0;
}
等级之题 N1(8.3)
题目传送门
思路
又是很明显的求递推公式
一共需要考虑三种情况(假设x为当前期望,y为下次期望)
1、黑球加一
放黑球,拿蓝球
概率:
2、黑球减一
放蓝球,拿黑球
概率:
3、黑球不变
放蓝球,拿蓝球
放黑球,拿黑球
所以可以求得下次的期望为
最后化简得
所以直接计算该公式即可,对于分母用逆元计算
代码
#include<cstdio>
#include<iostream>
using namespace std;
// #define TDS_ACM_LOCAL
#define ll long long
const int mod=1e9+7;
ll n, m, k, a, b;
ll quick_pow(ll a, ll b)
{
ll res = 1;
while (b)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
void solve(){
cin>>n>>m>>k>>a>>b;
ll x=(((((b*n)%mod -(a*n)%mod -(a*m)%mod)+mod)%mod *quick_pow(n+m, k))%mod +((a*(n+m)%mod)%mod *quick_pow(n+m+1, k))%mod)%mod;
ll y=(b*quick_pow(n+m+1, k))%mod;
y=quick_pow(y,mod-2);
cout<<x*y%mod<<endl;
return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
solve();
return 0;
}