gpt4 book ai didi

c++ - 模棱两可的期望值

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:26:52 28 4
gpt4 key购买 nike

我在网站上看到这个问题(我不会使用确切的措辞或提及网站),

Suppose a kid gets his pocket money on the 15th of every month, according to which day is it on that date, Lets say he gets 1 coin on Monday, 2 coins on Tuesday...7 coins on Sunday. What is the Expected number of coins he will get on the 15th of a random month?

起初我虽然每个的概率是 1/7 所以答案应该是 4,但它说错误答案。

然后想了想如何选择一个随机月份,并记得日历每 400 年重复一次,所以我想这可能与此有关,所以我编写了以下代码:

int Date(int mn,int yr)
{
if( ( yr%400==0 || (yr%100!=0 && yr%4==0) ) && mn==2)
return 29;
if(mn==2)
return 28;
if(mn==4 || mn==6 || mn==9 || mn==11)
return 30;
return 31;

}

int main()
{
double coins=0;
int wk=0;

for(int yr=1;yr<=400;yr++)
{
for(int mn=1;mn<=12;mn++)
{
for(int dt=1;dt<=Date(mn,yr);dt++)
{
if(dt==15)
coins += wk%7 +1;
wk++;
}
}
}

cout<<setprecision(10)<<coins/12/400;
}

输出-

4.001666667

宾果游戏!正确答案!但仔细想想,我意识到我选择星期一作为开始日,但它不能是任何一天吗?所以我对程序做了这个小改动 -

int main()
{
double total=0;

for(int i=0;i<7;i++)
{
int wk=i;
double coins=0;
for(int yr=1;yr<=400;yr++)
{
for(int mn=1;mn<=12;mn++)
{
for(int dt=1;dt<=Date(mn,yr);dt++)
{
if(dt==15)
coins += wk%7 +1;
wk++;
}
}
}
cout<<setprecision(10)<<coins/12/400<<endl;
total += coins;
}

cout<<endl<<setprecision(10)<<total/7/12/400;
}

输出-

4.001666667
3.998333333
4.000833333
3.998958333
4
4.001041667
3.999166667

4

太好了......现在真的很困惑......我们应该只接受它 4.00666 因为它是 0001 年 1 月 1 日星期一,或者问题可能有任何答案或者我在这里遗漏了一些非常重要的东西?

正确答案应该是什么?
如果不存在“正确”答案,那么您认为最合适的答案应该是什么?

最佳答案

您已经完成了所有必要的思考工作,甚至更多;但你过于笼统了。

I realized that i choose Monday to be the starting day, But couldn't it be any day?

不,如果问题是在这个宇宙中设置的,则不是。

should we just take it 4.00666 'cause it was Monday on 1st Jan 0001

“1 月 1 日”并不是一个明确指定的年份,因为那时公历和儒略历都不存在。

or the question could have any answer or am I missing something very important here?

What should be the correct answer for this?

这个问题只有一个正确答案,4.001666,因为工作日是如何与在这个宇宙中的年份对齐的。 1900 年 1 月 1 日(我们可以在任何我们喜欢的地方开始一个 400 年的循环,只要它是在采用公历之后)是一个星期一,所以更新你的代码 first main 来自

for(int yr=1;yr<=400;yr++)

for(int yr=1900; yr < 1900+400; yr++)

您将立即得到正确答案。


正如已经确定的那样,工作日与年份对齐的特定方式是导致此处“潜在”答案出现差异的原因。为什么the 13th of the month is more likely to fall on a Friday than on any other day of the week背后是同样的事情.

关于c++ - 模棱两可的期望值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44716878/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com