题目描述:
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;
}