ICPC North America Qualifier Contest 2015 B. Bobby's Bet(概率计算)

Bobby and Betty have a bet. Betty bets Bobby that he cannot roll an SS-sided die (having values 11 through SS) and obtain a value \geq R≥R on at least XX out of YY rolls. Betty has a variety of dice with different numbers of sides SS, and all her dice are fair (for a given die, each side's outcome is equally likely). In order to observe statistically rare events while still giving Bobby a reason to bet, Betty offers to pay Bobby WWtimes his bet on each encounter. For example, suppose Betty bets Bobby 11 bitcoin that he can't roll at least a 55 on a 66-sided die at least two out of three times; if Bobby does, she would give him W = 3W=3 times his initial bet (\text{i.e.}i.e.she would give him 33 bitcoins). Should Bobby take the bet (is his expected return greater than his original bet)?

Input

Input begins with an integer 1\leq N\leq 10 0001≤N≤10000, representing the number of cases that follow. The next NN lines each contain five integers, RR, SS, XX, YY , and WW. Their limits are 1\leq R\leq S\leq 201≤R≤S≤20, 1\leq X\leq Y\leq 101≤X≤Y≤10, and 1\leq W\leq 1001≤W≤100.

Output

For each case, output "yes" if Bobby's expected return is greater than his bet, or "no" otherwise. Bobby is somewhat risk averse and does not bet if his expected return is equal to his bet.

输出时每行末尾的多余空格,不影响答案正确性

样例输入1复制

2
5 6 2 3 3
5 6 2 3 4

样例输出1复制

no
yes

样例输入2复制

3
2 2 9 10 100
1 2 10 10 1
1 2 10 10 2

样例输出2复制

yes
no
yes

题意:

甲掷一个S面的骰子,若甲能够在Y次以内掷出 >= X次面值 >= R,则甲获得W倍的赌注,甲不想冒险,判断甲的期望回报是否大于他的原赌注,如果大于,他会和乙打赌(yes),否则不打赌(no)。

思路:

掷一个S面的骰子,计算在Y次以内掷出 >= X次面值 >= R 的概率 p ,设甲的原赌注为1,则甲的期望回报就是 W * p,判断是否W * p > 1,是yes,不是no

(发现分母都是S ^ Y,进行了统一处理,一开始为了防爆,先除后乘的,竟然WA了,然后换成先乘后除就AC了…???

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

ll c[12][12];

void init()
{
    c[0][0] = 1;
    for(int i = 1; i < 12; ++i)
    {
        c[i][0] = c[i][i] = 1;
        for(int j = 1; j < i; ++j)
        {
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
        }
    }
}

ll qpow(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
        {
            ans = ans * a;
        }
        a = a * a;
        b /= 2;
    }
    return ans;
}

int main()
{
    init();
    ll n, r, s, x, y, w;
    scanf("%lld", &n);
    while(n--)
    {
        scanf("%lld%lld%lld%lld%lld", &r, &s, &x, &y, &w);
        ll a = s - r + 1;
        ll b = r - 1;
        ll down = qpow(s, y);
        double p = 0;
        for(ll i = x; i <= y; ++i)
        {
            p += 1.0 * c[y][i] * qpow(a, i) * qpow(b, y - i) / down;
        }
        p = 1.0 * p * w;
        if(p > 1)
        {
            cout<<"yes"<<'\n';
        }
        else
        {
            cout<<"no"<<'\n';
        }
    }
    return 0;
}
/*
2
5 6 2 3 3
5 6 2 3 4
3
2 2 9 10 100
1 2 10 10 1
1 2 10 10 2
*/

 

全部评论

相关推荐

嵌入式的小白:有道理哈,这种就看能不能捞
点赞 评论 收藏
分享
10-19 10:28
已编辑
西南石油大学 后端工程师
团孝子已上线feeling:面了很多家公司,能感受到目前只有小公司+外包喜欢问八股。大厂虽然也问八股,但是是从实习、项目中进行提问,并且大厂会问很深,面试官也会对你的回答进行思考➕追问,所以准备大厂面试前一定要备好相关资料。对于算法,我做的是codetop前100+力扣hot100+力扣高频150,面试中实感hot100就足够,基本上只要是hot100就秒答。对于项目和八股,我做的也是烂大街的星球项目,八股则是看小林和问ai,自己也写了很多技术博客和画了很多思维导图,并且自己也尝试用嘴巴说出来,不只停留于纸面。运气也很重要,必须要让面试官/HR看到简历才行,所以建议投递时间是下午两点。tl:第一岗位9.9&nbsp;投递9.10&nbsp;一面(一面评价:最近见过最强的大三,结束五分钟后约二面,都晚上九点了不下班吗)9.11&nbsp;二面(三道算法a出两道,反问评价:经验不够等横向,我实习生要啥经验)9.21挂(实习时间过短+其他原因,想要一年实习的,为什么不招个正职)第二岗位10.10投递10.11约面(主管打电话,说看到我之前投递记录了想要我挂qa职进去干后端,同意)10.14&nbsp;一面(无八股,主动说确实很强,意愿很强)10.16&nbsp;oc其余,友邦,东软,东华,惠择,用友oc已拒京东测开一面挂(投后端被测开捞)腾讯测试已拒(投后端被测开捞)ps:表扬惠择的主管面,没怎么问技术(可能是一面面试官沟通过了),全程一起讲大道理,解答了心中很多疑惑,也告诉我以面试官角度来看怎么选候选人,如果可以下次一定选惠择
HeaoDng:美团好像可以触发一面通
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务