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

2014
ACM-ICPC Beijing Invitational Programming Contest

题意::一个人在玩桌面足球,有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;
}
时间: 2024-11-09 00:59:07

BNU 34986 Football on Table的相关文章

bnu 34986 Football on Table(数学+暴力)

题目连接:bnu 34986 Football on Table 题目大意:给出桌子的大小L,W,然后是球的起始位置sx,sy,以及移动的向量dx,dy,然后给出n,表示有n个杆,对于每个杆,先给出位置x,以及杆上有多少个小人c,给出小人的宽度,再给出c个小人间的距离.现在问说球有多少个概率可以串过所有人. 解题思路:对于每个杆求无阻挡的概率,注意概率 = 空隙 / 可移动的范围大小,而不是W.其他就水水的. #include <cstdio> #include <cstring>

2014北京邀请赛 F Football on Table

题目来源: http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34986 题意: 一个人在玩桌面足球,有m行球员,每行球员有ai个,给出每个球员的宽度和相邻球员之间的距离,球从最左边射出,给出球的起点坐标跟方向向量,问能够到达最右边的概率. 思路:球员的相对位置固定,球员可以移动一定的距离.计算球经过球员的概率, 用1 - 球经过球员的概率 即为 可以穿过的概率. 枚举一遍所有行. 代码如下: const int Max_N = 105 ; dou

2014 BNU邀请赛F题(枚举)

Football on Table 题意:一些杆上有人,人有一个宽度,然后现在有一个球射过去,要求出球不会碰到任何人的概率 思路:计算出每根杆的概率,之后累乘,计算杆的概率的时候,可以先把每块人的区间长度再移动过程中会覆盖多少长度累加出来,然后(1?总和/可移动距离)就是不会碰到的概率 代码: #include <stdio.h> #include <string.h> #include <math.h> const double eps = 1e-8; int t,

LeetCode 1212. Team Scores in Football Tournament

Table: Teams +---------------+----------+ | Column Name | Type | +---------------+----------+ | team_id | int | | team_name | varchar | +---------------+----------+ team_id is the primary key of this table. Each row of this table represents a single

美国政府关于Google公司2013年度的财务报表红头文件

请管理员移至新闻版块,谢谢! 来源:http://www.sec.gov/ 财务报表下载↓ 此文仅作参考分析. 10-K 1 goog2013123110-k.htm FORM 10-K UNITED STATES SECURITIES AND EXCHANGE COMMISSION Washington, D.C. 20549     FORM 10-K (Mark One)       ý ANNUAL REPORT PURSUANT TO SECTION 13 OR 15(d) OF TH

ios 获取当前视图第一响应者

Football on Table 题意:一些杆上有人,人有一个宽度,然后现在有一个球射过去,要求出球不会碰到任何人的概率 思路:计算出每根杆的概率,之后累乘,计算杆的概率的时候,可以先把每块人的区间长度再移动过程中会覆盖多少长度累加出来,然后(1?总和/可移动距离)就是不会碰到的概率 代码: #include <stdio.h> #include <string.h> #include <math.h> const double eps = 1e-8; int t,

顺序栈的c语言实现

Football on Table 题意:一些杆上有人,人有一个宽度,然后现在有一个球射过去,要求出球不会碰到任何人的概率 思路:计算出每根杆的概率,之后累乘,计算杆的概率的时候,可以先把每块人的区间长度再移动过程中会覆盖多少长度累加出来,然后(1?总和/可移动距离)就是不会碰到的概率 代码: #include <stdio.h> #include <string.h> #include <math.h> const double eps = 1e-8; int t,

hadoop学习;block数据块;mapreduce实现例子;UnsupportedClassVersionError异常;关联项目源码

Football on Table 题意:一些杆上有人,人有一个宽度,然后现在有一个球射过去,要求出球不会碰到任何人的概率 思路:计算出每根杆的概率,之后累乘,计算杆的概率的时候,可以先把每块人的区间长度再移动过程中会覆盖多少长度累加出来,然后(1?总和/可移动距离)就是不会碰到的概率 代码: #include <stdio.h> #include <string.h> #include <math.h> const double eps = 1e-8; int t,

CodeForces 200C Football Championship(暴力枚举)

C. Football Championship time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Any resemblance to any real championship and sport is accidental. The Berland National team takes part in the local