集训第六周 数学概念与方法 UVA 11722 几何概型

---恢复内容开始---

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471

题意,两辆火车,分别会在[t1,t2],[s1,s2]的时间段停留在同一个站点w分钟,问两辆火车能够在这个站点相遇的概率。

思路,枚举每一种情况,把两辆火车的相交区间画出来,然后求都在这个区间的概率

#include"iostream"
#include"cstdio"
#include"cmath"
using namespace std;

int ca;
double t1,t2,s1,s2,w,ans;

double caculate(double b)
{
    int y1=t1+b,y2=t2+b;
    if(y2<s1) return 0;
    if(y1<s1)
    {
        if(y2<s2) return 0.5*(y2-s1)*(y2-s1);
        else return 0.5*(s2-s1)*(2*y2-s1-s2);
    }
    if(y1<s2)
    {
        if(y2<s2) return 0.5*(t2-t1)*(y1-s1+y2-s1);
        else return (t2-t1)*(s2-s1)-0.5*(s2-y1)*(s2-y1);
    }
    return (t2-t1)*(s2-s1);
}

void Init()
{
   scanf("%lf%lf%lf%lf%lf",&t1,&t2,&s1,&s2,&w);
}

void Work()
{
 ans=(caculate(w)-caculate(-w))/((t2-t1)*(s2-s1));
}

void Print()
{
    printf("Case #%d: %.8f\n",ca++,ans);
}

int main()
{
    int T;
    ca=1;
    cin>>T;
    while(T--)
    {
     Init();
     Work();
     Print();
    }
    return 0;
}

---恢复内容结束---

时间: 2024-08-26 13:59:38

集训第六周 数学概念与方法 UVA 11722 几何概型的相关文章

集训第六周 数学概念与方法 UVA 11181 条件概率

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概率会给出,问这一群人去买东西,第i个人属于r之中的概率是多少 思路:首先得了解什么是条件概率. 条件概率:事件A在事件B成立的基础上再成立的概率,公式为:P(A|B)=P(A*B)/P(B) 可以照着题目案例1进行分析: 输入 0.10 0.20 0.30 输出 0.413043 0.739130

集训第六周 数学概念与方法 数论 筛素数 G题

Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.  问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数.  给定一个区间,你能计算出这个区间内有多少个美素数吗? Input 第一行输入一个正整数T,表示总共有T组数据(T <= 10000). 接下来共T行,每行输入两个整数L,R(1<= L <= R <= 10

集训第六周 数学概念与方法 概率 F题

Submit Status Description Sometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party where there are 23 people including you. What is the probability that at least two peopl

集训第六周 数学概念与方法 概率 数论 最大公约数 G题

Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into

集训第六周 数学概念与方法 计数 排列 L题

Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情.如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题并不

集训第六周 数学概念与方法 概率 N题

N - 概率 Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks.

集训第六周 数学概念与方法 数论 线性方程 I题

Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Trees Trees are Shaking, Leaves are Falling. Lovers Walk passing, and so are You. ................................Write in English class by yifenfei Gir

集训第六周 古典概型 期望 D题 Discovering Gold 期望

Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice a

集训第六周 E题

E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once.