bnu 34986 Football on Table(數學+暴力)

來源:互聯網
上載者:User

標籤:style   class   code   http   tar   color   

題目串連: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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.