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>
#include <cmath>
#include <algorithm>

using namespace std;
const double eps = 1e-8;
const int N = 205;

double L, W;
double sx, sy, dx, dy;
double d[N];

double solve () {

    int n, c;
    double w, ans = 1;

    scanf("%d", &n);

    while (n--) {
        scanf("%lf%d", &w, &c);
        double r = sy + w * dy / dx;
        double s = 0;
        c = 2 * c - 1;

        for (int i = 0; i < c; i += 2)
            scanf("%lf", &d[i]);
        for (int i = 1; i < c; i += 2)
            scanf("%lf", &d[i]);
        for (int i = 0; i < c; i++)
            s += d[i];

        double l = W - r;
        double rec = 0;

        if (l > s) {
            rec += (l - s);
            l = 0;
        } else {
            l = s - l;
        }

        if (r > s) {
            rec += (r - s);
            r = s;
        }

        s = 0;
        for (int i = 0; i < c; i++) {
            double tmp = s + d[i];
            if (i&1) {
                double add = min(r, tmp) - max(s, l);
                rec += max(add, (double)0);
            }
            s = tmp;
        }

        ans *= rec / (W-s);
    }
    return ans;
}

int main () {
    int cas;
    scanf("%d", &cas);
    for (int i = 1; i <= cas; i++) {
        scanf("%lf%lf", &L, &W);
        scanf("%lf%lf%lf%lf", &sx, &sy, &dx, &dy);
        printf("Case #%d: %.5lf\n", i, solve());
    }
    return 0;
}

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

时间: 2024-11-07 01:55:05

bnu 34986 Football on Table(数学+暴力)的相关文章

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 f

uva 1069 - Always an integer(数学+暴力)

题目链接:uva 1069 - Always an integer 题目大意:给出一个多次多项式,问说是否对于任意正整数n来说结构均为整数. 解题思路:首先处理出字符串,然后枚举n从1到k+1判断即可,k为多项式中出现过的最大幂数指. P为多项式,d为除数,k为多项式中最大的次数 当k=0时,P中不存在n变量,所以直接计算判断即可 当k=1时,P是一次多项式,那么P(n+1)?P(n)=a,a为常数,也就是说P(i)为等差数列,如果首项P(1)和公差P(2)-P(1)为d的倍数即可,等价与判断P

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

HDU 2058 The sum problem (数学+暴力)

题意:给定一个N和M,N表示从1到N的连续序列,让你求在1到N这个序列中连续子序列的和为M的子序列区间. 析:很明显最直接的方法就是暴力,可是不幸的是,由于N,M太大了,肯定会TLE的.所以我们就想能不能优化一下,找一个范围.想到这是一个连续的序列而且是从1开始的,这不就是一个等差数列么,公差是1罢了.由求和公式得Sn = (a1+an) * n / 2;所以说n最大就是sqrt(M*2)(想一想为什么),因为a1+an 一定是大于n的.如果我们取区间的和,那么Sn = (ai+aj) * (j

UVA11565 Simple Equations【数学+暴力】

Let us look at a boring mathematics problem. :-) We have three different integers, x, y and z, which satisfy the following three relations: ? x + y + z = A ? xyz = B ? x^2 + y^2 + z^2 = C You are asked to write a program that solves for x, y and z fo

poj 1543 &amp; HDU 1334 &amp; ZOJ 1331 Perfect Cubes(数学 暴力大法好)

题目链接:http://poj.org/problem?id=1543 Description For hundreds of years Fermat's Last Theorem, which stated simply that for n > 2 there exist no integers a, b, c > 1 such that a^n = b^n + c^n, has remained elusively unproven. (A recent proof is believ

数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

题目传送门 1 /* 2 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <iostream> 8 #include <cmath> 9 #include <vector> 10 using namespace std; 11

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