BNU 34986 Football on Table

Posted gavanwanggw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BNU 34986 Football on Table相关的知识,希望对你有一定的参考价值。

"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-fibre 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 ai 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).
 

Input

The 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 integer ai,(0<xi<L, 1 ≤ ai ≤ 100) denoteing the x-coordinate of the ith row and the number of players at the ith row.
    • The second line contains ai numbers, the jth number wj denotes the width of the jth (from bottom to top) player at the ith row.
    • The third line contains ai - 1 numbers, the jth number dj denotes the distance between the jth player and the (j+1)th player. If ai equals 1, this line will be a blank line.
We guarantee that ∑wj + ∑dj + 1< W
 

Output

For each case, first output the case number as "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

2
8.0 10.0
0.0 5.0 2.0 -0.1
1
3.0 2
2.0 2.0
1.0
8.0 10.0
0.0 5.0 2.0 0.0
2
3.0 2
2.0 2.0
1.0
4.0 3
2.0 1.0 2.0
1.0 1.0

Sample Output

Case #1: 0.23000
Case #2: 0.13333

Hint

技术分享
The black solid lines denote the table.
The dashed line denotes the bar.
The gray lines denote the players.
The dot-dashed line denote the trajectory of the ball.
 

Source


题意::一个人在玩桌面足球,有m行球员。每行球员有ai个,给出每一个球员的宽度和相邻球员之间的距离,球从最左边射出,给出球的起点坐标跟方向向量,问可以到达最右边的概率。

思路:看懂题意就好做点了,枚举每行能够碰到球的距离。然后概率求反

#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的主要内容,如果未能解决你的问题,请参考以下文章

2018bnu校赛总结

BNU 4096 逆序 思维题

2018BNU校赛总决赛

BNU 34990 Justice String (hash+二分求LCP)

BNU 51275 道路修建 Large 并查集

bnu j just a string