SGU144 Meeting

SGU144 Meeting

题目大意

两个人约会见面,他们可能在X点到Y点之间的任意时刻到达
先到的人会等另一个人Z分钟,问两人能够见面的概率

算法思路

几何概型,答案等于合法区域中 | X - Y | <= Z 表示区域的面积,除以合法区域的面积

时间复杂度: O(1)

代码

/** * Copyright © 2015 Authors. All rights reserved. * * FileName: 144.cpp * Author: Beiyu Li <[email protected]> * Date: 2015-06-18 */
#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)

typedef long long LL;
typedef pair<int, int> Pii;

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

int main()
{
        int x, y;
        double z;
        scanf("%d%d%lf", &x, &y, &z);
        double l = 60 * (y - x);
        double p = (l - z) / l;
        printf("%.7f\n", 1 - p * p);

        return 0;
}

你可能感兴趣的:(概率,sgu)