J + 1 <W outputfor each case, first output the case number"Case # X:", And X is the case number. then output the result rounded to 5 digits after the decimal point, representing the possibility of this shoot turning to a goal, in other words, that the ball does not touch any player. sample Input28.0 10.00.0 5.0 2.0 -0.113.0 22.0 2.01.08.0 10.00.0 5.0 2.0 0.023.0 22.0 2.01.04.0 32.0 1.0 2.01.0 1.0
Sample outputCase #1: 0.23000Case #2: 0.13333
Hintthe black solid lines denote the table. The dashed line denotes the bar. The gray lines denote the players. The dot-dashed line denote the trajections of the ball. source2014 ACM-ICPC Beijing Invitational Programming Contest
Q: A man is playing desktop football with m-line players and each line of players has AI. The distance between the width of each player and the adjacent players is displayed. The ball is shot from the leftmost, the START coordinate and direction vector of the ball are given, and the probability of reaching the rightmost is asked.
Idea: understand the meaning of the question to make it easier, enumerate the distance from each row to the ball, and then calculate the probability inverse.
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int maxn = 105;double w[maxn], tail[maxn], pos[maxn];int main() {int t, m, cas = 1;double W, L, X, Y, dx, dy, dis;scanf("%d", &t);while (t--) {double ans = 1.0;scanf("%lf%lf", &L, &W);scanf("%lf%lf%lf%lf", &X, &Y, &dx, &dy);scanf("%d", &m);while (m--) {double sum = 0.0;pos[0] = 0.0;double x;int n;scanf("%lf%d", &x, &n);double y = Y + dy * (x - X) / dx;for (int i = 0; i < n; i++) {scanf("%lf", &w[i]);sum += w[i];}tail[0] = w[0];for (int i = 1; i < n; i++) {scanf("%lf", &dis);pos[i] = pos[i-1] + w[i-1] + dis;tail[i] = pos[i] + w[i];sum += dis;}double cnt = 0.0, len = 0.0;double mv = W - sum;for (int i = 0; i < n; i++) {cnt = 0.0;if ((pos[i] <= y) && (tail[i] + mv) >= y) {if (tail[i] >= y) cnt = (pos[i] + mv <= y) ? mv : (y - pos[i]);else cnt = (pos[i] + mv >= y) ? w[i] : (tail[i] - y + mv);}len += cnt;}if (mv == 0.0) {ans = 0;break;}else ans = ans * (mv - len) / mv;}printf("Case #%d: %.5lf\n", cas++, ans);}return 0;}
BNU 34986 football on table