• 跳跳机器人


    跳跳机器人

    小R、小B和小D分别研制出三个不同的跳跳机器人。小R的机器人一次弹跳的距离是([l_1,r_1])区间内的等概率随机的整数,小B的机器人一次弹跳的距离是([l_2,r_2])区间内的等概率随机的整数,小D的机器人一次弹跳的距离是([l_3,r_3])区间内的等概率随机的整数。现在三个机器人分别弹跳了一次,设小R的机器人弹跳的距离为(x_1),小B的机器人弹跳的距离为(x_2),小D的机器人弹跳的距离为(x_3),求(x_1≥x_2≥x_3)的概率。

    看起来这道题是不是很难做。。其实因为总共只有三个机器人,最多只有五个区间,枚举机器人在哪个区间即可。注意double和long long的精度。。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    typedef long long LL;
    LL t, cntq, q[7], l[3], r[3];
    double ans;
    
    //这里不能变成double。。可能是卡精度吧
    LL c2(LL x){ return x*(x-1)/2; }
    LL c3(LL x){ return x*(x-1)*(x-2)/6; }
    
    int main(){
        LL a, b, c; scanf("%lld", &t);
        for (LL tt=0; tt<t; ++tt){
            ans=0; memset(q, 0, sizeof(q));
            for (LL i=0; i<3; ++i){
                scanf("%lld%lld", &l[i], &r[i]);
                q[i*2]=l[i]; q[i*2+1]=r[i]+1; }
            sort(q, q+6); cntq=unique(q, q+6)-q;
            for (LL i=0; i<cntq-1; ++i) for (LL j=0; j<=i; ++j) {
                if (q[i]<l[0]||q[i+1]>(r[0]+1)) continue;
                if (q[j]<l[1]||q[j+1]>(r[1]+1)) continue;
                for (LL k=0; k<=j; ++k){
                    if (q[k]<l[2]||q[k+1]>(r[2]+1)) continue;
                    a=q[i+1]-q[i]; b=q[j+1]-q[j]; c=q[k+1]-q[k];
                    if (i==j&&j==k) ans+=c3(a)+2*c2(a)+a; else
                    if (i!=j&&j!=k) ans+=a*b*c; else
                    if (i==j) ans+=(c2(a)+a)*c; else
                    if (j==k) ans+=(c2(c)+c)*a;
                }
            }
            for (int i=0; i<3; ++i) ans/=r[i]-l[i]+1;
            printf("%.9lf
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    洛谷 P2969 [USACO09DEC]音符Music Notes
    洛谷 P2646 数数zzy
    洛谷 P1605 迷宫
    洛谷 P1157 组合的输出
    洛谷 P1449 后缀表达式
    洛谷 P1205 [USACO1.2]方块转换 Transformations
    洛谷 P1599 结算日
    洛谷 P2909 [USACO08OPEN]牛的车Cow Cars
    洛谷 P2118 比例简化
    3.2、spark集群运行应用之第三方jar的处理方式
  • 原文地址:https://www.cnblogs.com/MyNameIsPc/p/7772117.html
Copyright © 2020-2023  润新知