Football on Table
Some people on the pole have a width, and now there is a ball shot. It is required that the ball won't hit anyone.
Idea: calculate the probability of each pole, and then multiply it. When calculating the probability of the pole, We can first accumulate the length of each individual's range and then accumulate the number of covers during the moving process, then (1? Sum/movable distance) is the probability of not encountering
Code:
#include
#include
#include
const double eps = 1e-8;int t, n;double l, w, x, y, dx, dy;struct gan { double len; int num; double r[105]; double d[105]; double sumd; void init() { sumd = 0; memset(r, 0, sizeof(r)); memset(d, 0, sizeof(d)); }} g;double cal(gan g) { double yy = g.len * dy / dx + y; double yi = w - g.sumd; double down = 0, up = g.r[0]; double ans = 0; for (int i = 0; i < g.num; i++) { if (up + yi > yy && down < yy) { if (up > yy) { if (down + yi > yy) ans += yy - down; else ans += yi; } else { if (down + yi > yy) ans += g.r[i]; else ans += yi - (yy - up); } } down = up + g.d[i]; up = down + g.r[i + 1]; } return 1.0 - ans / yi;}int main() { int cas = 0; scanf("%d", &t); while (t--) { double ans = 1; scanf("%lf%lf", &l, &w); scanf("%lf%lf%lf%lf", &x, &y, &dx, &dy); scanf("%d", &n); for (int i = 0; i < n; i++) { g.init(); scanf("%lf%d", &g.len, &g.num); for (int j = 0; j < g.num; j++) { scanf("%lf", &g.r[j]); g.sumd += g.r[j]; } for (int j = 0; j < g.num - 1; j++) { scanf("%lf", &g.d[j]); g.sumd += g.d[j]; } g.d[g.num - 1] = 0; ans *= cal(g); } printf("Case #%d: %.5lf\n", ++cas, ans); } return 0;}