BNU 34986 football on table

Source: Internet
Author: User
Tags dashed line

"Bored? Let's play table football! "The table football is played on a rectangular table, usually contains m rows of players which are plastic, metal, wooden, or sometimes carbon-fiber figures mounted on vertical metal bars. after playing table football for hours, we decide to take a rest. and the state of the table remains random, that means each bar is placed at any legal position with equal possibilities (players can't be outside The table and a bar is fixed at a row). Now I'm wondering if the goal-keeper shoot a ball, what's the possibility of this shoot turning to a goal? (If the ball did not touch any player, then I made a goal). Let's assume there is I players on the ITh row (counted from left to right ). and we know the width of each player and the distance between two players. (To simplify the problem, we ignore the thickness of the players, in other words, we consider the players as vertical segments. then we treat the football as a point, moving along a straight line and will not touch the boundary of the table ). inputthe first line contains an integer T, which denotes the number of test cases. for each test case:
  • The first line contains two numbers L, w (1 ≤ L, W ≤ 108), denoting the length and the width of the table. (the lower left corner of the table is (0, 0), and the top right corner of the table is (L, W )).
  • The second line contains four number X, Y, dX, dY. (x, y) denotes the initial position of the ball and (dX, dY) denotes the shooting direction. (X will always be zero, 0 ≤ y ≤ W, dX> 0 ).
  • The third line contains an integer m (1 ≤ m ≤ 10), the number of rows of the players.
  • Following M Blocks, for the ITh block,
    • The first line contains a number xI and an integerI, (0 <XI <L, 1 ≤(I ≤ 100) denoteing the X-coordinate of the ITh row and the number of players at the ITh row.
    • The second line containsI numbers, the JTh number WJ Denotes the width of the JTh (from bottom to top) player at the ITh row.
    • The third line containsI-1 numbers, the JTh number dJ Denotes the distance between the JTh player and the (J + 1)Th player. IfI equals 1, this line will be a blank line.
We guarantee that Σ WJ + Σ dJ + 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 Input
28.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 output
Case #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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.