sgu 144

39 篇文章 0 订阅
18 篇文章 0 订阅

题目描述:

144. Meeting

time limit per test: 0.5 sec.
memory limit per test: 4096 KB

Two of the three membersof the winning team of one of the ACM regional contests are going to meetin order to train for the upcoming World Finals. They decided that theywill meet sometime between X o'clock and Y o'clock. Becausethey never get anywhere on time (they were late even on the day of theregional contest), they did not set an exact time when they will meet.However, they decided that the one who gets first at the meeting pointwill not wait more than Z minutes for the other one (they calculatedthat, if the other one will not come within Z minutes from the arrivalof the first of them, then it is very probable that he will not show upat all).
Knowing that, in theend, both of them will show up at some time between X o'clock andYo'clock (not necessarily after an integer number of minutes), compute whichis the probability that they will actually meet.

Input

The input will contain2 integer numbers X and Y (0<=X<Y<=24)and one real number Z ( 0 < Z <= 60*(Y-X) ).

Output

You should outputthe required probability with 7 decimal digits (rounded accordingto the 8th decimal digit).

Sample Input

11 12 20.0

Sample Output

0.5555556


题意就是求在某区间段到达且时间差值小于z的概率;

高中数学题难度吧。


很容易想到就是用二维坐标轴方法求解。

假设两人到达的时间是 x y

且 x<y 那么 y-x <=z 就是一条直线啊。


最后的公式 : p= 1-(y-x-z)^2/(y-x)^2 ;


贴代码时间:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<algorithm>
#include<vector>
#include<cstdlib>

#define inf 0xfffffff
#define CLR(a,b) memset((a),(b),sizeof((a)))
#define FOR(a,b) for(int a=1;a<=(b);(a)++)

using namespace std;
int const nMax = 1010;
int const base = 10;
typedef int LL;
typedef pair<LL,LL> pij;

//    std::ios::sync_with_stdio(false);


double x,y,z;

int main(){
    cin>>x>>y>>z;
    y-=x;
    y*=60.0;
    z=y-z;
    double ans=1-1.0*z*z/(1.0*y*y);
    printf("%.7lf\n",ans);
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值