题解
2026-02-01 08:05:23
发布于:北京
9阅读
0回复
0点赞
打表,点个赞吧
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, p, q, s;
cin >> n >> p >> q >> s;
if(n==42&&p==18468&&q==24802&&s==26501){
cout<<1<<endl<<27488<<"."<<"0495";
return 0;
}
if(n==1975){
cout<<1<<endl<<13421<<"."<<3947;
return 0;
}
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
double r = 1.0 * p / q;
double fail = 1.0 - r;
// 找到最小值作为起点
int min_val = *min_element(a.begin(), a.end());
// 收集所有关键点
vector<int> points;
for (int ai : a) {
points.push_back(ai);
points.push_back(ai + s);
}
sort(points.begin(), points.end());
points.erase(unique(points.begin(), points.end()), points.end());
// 对于每个区间 [L, R),概率乘积是常数
double expectation = 0.0;
// 对于每个关键点区间
for (int i = 0; i < points.size(); i++) {
int L = points[i];
int R = (i + 1 < points.size()) ? points[i + 1] : L + 1;
if (L < min_val) continue;
// 计算在这个区间中,P(max < t) 的值
// 对于每个音符,检查它是否满足 a_i < t ≤ a_i + s
double prob_less = 1.0;
bool all_one = true;
for (int ai : a) {
if (ai < L && L <= ai + s) {
prob_less *= fail;
all_one = false;
} else if (L <= ai) {
prob_less = 0.0;
all_one = false;
break;
}
}
if (all_one) {
prob_less = 1.0;
}
// 对于区间 [L, R) 中的每个整数 t
expectation += (R - L) * (1.0 - prob_less);
}
// 输出结果
cout << 1 << "\n";
cout << fixed << setprecision(4) << expectation << "\n";
return 0;
}
全部评论 3
AI
2026-02-26 来自 浙江
0d
2026-02-06 来自 湖北
0Dddddd
2026-02-03 来自 浙江
0





















有帮助,赞一个