生日问题 [英] Birthday Problem

查看:60
本文介绍了生日问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了这个问题以获得额外的功劳而我只是卡住了!

顺便说一句 - 我不是要求源代码而我也没有要求任何人这样做

我的作业,因为我想学习..我只需要一两个提示就可以获得

移动,我需要知道我到目前为止所写的内容是否导致我

正确的方向〜


好​​的 - 问题是找出一个房间里需要多少人

95%的可能性是某人那个房间将与我的生日相匹配


我写了一个程序,计算任意2个b $ b b bdaydays匹配的百分比,但这不是一回事:)


这是我到目前为止:

#include" stdafx.h"

#include< time.h>

#include< iostream>

使用命名空间std;


int _tmain(int argc,_TCHAR * argv [])

{

int sample [1000];

int i = 1,j = 1;

int a = 0;

srand((无符号)时间(NULL));


while(a!= 325)

{sample [i] = rand()%365+ 1;

// cout<<" "<<< sample [i];

a = sample [i];

i ++;

if(a == 325) cout<<" \ n \ n \ n匹配"<< a<<<<<<<<<<<< at"<<<<<<" \ n";

}


返回0;


这会将1-365中的随机数放入数组中 - 读取数组并且

尝试检测完全匹配

问题是匹配是这样的随机 - 我怎么想出一个95%的机会?有没有确切的答案?


正如我所说的 - 只需要一些提示继续前进..


任何回复都将受到赞赏,


谢谢,


桑德拉

I was given this problem for extra credit and I am just stuck !
BTW - I am not asking for source code and I am not asking anyone to do
my homework as I do want to learn .. I just need a hint or two to get
moving and I need to know if what I have written so far is leading me
in the right direction ~

Ok - The problem is to find out how many people need to be in a room
for a 95% chance that someone in that room will match my birthday

I wrote a program that will calculate that percentage for any 2
bithdays to match, but that is not the same thing :)

Here is what I have so far:
#include "stdafx.h"
#include <time.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int sample[1000];
int i=1,j=1;
int a =0;
srand( (unsigned)time( NULL ) );

while (a != 325)
{ sample[i]=rand()%365+1;
//cout<<" "<<sample[i];
a = sample[i];
i++;
if (a==325) cout<<"\n\n\n Match "<<a<<" at "<<i<<"\n";
}

return 0;

This puts random numbers from 1-365 in an array - reads the array and
tries to detect an exact match
The problem is that the match is so random - how do I come up with a
95% chance? Is there any exact answer ?

As I said - just need some hints to move along..

Any replies will be appreciated,

Thanks,

Sandra

推荐答案

桑德拉写道:
Sandra writes:
我得到了这个问题以获得额外的功劳而且我只是卡住了!
顺便说一下 - 我不是要求源代码,我不是要求任何人做的事情我的作业,因为我想学习..我只需要一两个提示即可移动,我需要知道我到目前为止所写的内容是否正在朝着正确的方向引导我〜

好的 - 问题是找出有多少人需要在一个房间内,因为那个房间里的人有95%的机会与我的生日相匹配

我写了一个程序来计算任何2个bithdays匹配的百分比,但这不是一回事:)

这是我到目前为止:
< ;剪断>这将1-365中的随机数放入数组中 - 读取数组并尝试检测完全匹配
问题是匹配是如此随机 - 我如何想出一个
95%几率?有没有确切的答案?
I was given this problem for extra credit and I am just stuck !
BTW - I am not asking for source code and I am not asking anyone to do
my homework as I do want to learn .. I just need a hint or two to get
moving and I need to know if what I have written so far is leading me
in the right direction ~

Ok - The problem is to find out how many people need to be in a room
for a 95% chance that someone in that room will match my birthday

I wrote a program that will calculate that percentage for any 2
bithdays to match, but that is not the same thing :)

Here is what I have so far: <snip> This puts random numbers from 1-365 in an array - reads the array and
tries to detect an exact match
The problem is that the match is so random - how do I come up with a
95% chance? Is there any exact answer ?




你的开局不好。有两种方法可以解决这个问题,模拟它并计算它。我认为你的导师想要你计算它并且你需要模仿它。


在一个房间里有两亿人。

第一个人不会匹配任何人。下一个人将有一个

*不同*生日,概率为364/365。下一个363/365。等等。


现在编写一个程序,监控95%的阈值。我认为

还有一个算法* *但是我不认为这是想要的。


是的,有一个确切的答案问题提出。



You are off to a bad start. There are two ways to approach this, simulate
it and compute it. I think your instructor want you to compute it and you
are simulating.

Given a bazillion people in a room.
The fist person will not match anyone. The next person will have a
*different* birthday with probability 364/365. The next 363/365. And so on.

Now write a program, monitoring for the 95% threshold as you go. I think
there is an algorithm *too* but I don''t think that is wanted here.

Yes, there is an exact answer to the question posed.


" Sandra" < S ******** @ mindspring.com>。写了
"Sandra" <s.********@mindspring.com> wrote
我给了这个问题额外的功劳和
我只是卡住了!顺便说一句 - 我不是要求
源代码,我不是要求任何人做我的作业,因为我想学习..我只是需要一两个提示才能动起来我需要知道我到目前为止所写的内容是否正在朝着正确的方向发展〜

好的 - 问题是找出有多少人需要在一个房间里有95%的机会
那个房间里的人会和我的生日相匹配

我写了一个程序来计算任意2个生日的百分比
匹配,但这是不一样的东西:)

这是我到目前为止:

#include" stdafx.h"
#include< time.h>
#include< iostream>
使用命名空间std;

int _tmain(int argc,_TCHAR * argv [])
{
int sample [1000];
int i = 1,j = 1;
int a = 0;
srand((unsigned)time(NULL));

while(a!= 325)
{sample [i] = rand()%365 + 1;
// cout<<" "<<< sample [i];
a = sample [i];
i ++;
if(a == 325)cout<<" \ nn n \ n匹配"<< a<<<<<< at"<<<<" \ n" ;;
}

返回0;

这会输入1-365的随机数在一个
数组中 - 读取数组并尝试检测完全匹配问题是匹配是如此随机 - 我如何想出95%的机会?有没有确切的答案?

正如我所说 - 只需要一些提示就可以继续..
I was given this problem for extra credit and
I am just stuck ! BTW - I am not asking for
source code and I am not asking anyone to do
my homework as I do want to learn .. I just
need a hint or two to get moving and I need
to know if what I have written so far is leading
me in the right direction ~

Ok - The problem is to find out how many
people need to be in a room for a 95% chance
that someone in that room will match my birthday

I wrote a program that will calculate that percentage
for any 2 bithdays to match, but that is not the same
thing :)

Here is what I have so far:
#include "stdafx.h"
#include <time.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int sample[1000];
int i=1,j=1;
int a =0;
srand( (unsigned)time( NULL ) );

while (a != 325)
{ sample[i]=rand()%365+1;
//cout<<" "<<sample[i];
a = sample[i];
i++;
if (a==325) cout<<"\n\n\n Match "<<a<<" at "<<i<<"\n";
}

return 0;

This puts random numbers from 1-365 in an
array - reads the array and tries to detect an
exact match The problem is that the match is
so random - how do I come up with a 95%
chance? Is there any exact answer ?

As I said - just need some hints to move along..




这是一个应该是的问题除非你被特别告知要使用蛮力,否则分析而不是粗暴地解决。如果它是

后者,请考虑一种天真的方法:手动执行:检查

组的大小为1的概率。然后检查组是否大小为2.依此类推,直到

你达到95%。有更复杂的方法可以搜索这个空间,但是你最好每次只做一步(没有双关语)。再次,

如果你有选择,解析它解决(

概率上的任何开头文本就会有这样的例子)。


Claudio Puviani



This is a problem that should be solved analytically rather than with brute
force, unless you were specifically told to use brute force. If it''s the
latter, consider a naive way to do it by hand: check the probability if the
group is of size 1. Then check if the group is of size 2. And so on, until
you hit 95%. There are more sophisticated ways to search that space, but
you''re better off taking things one step at a time (no pun intended). Again,
if you have a choice, solve it analytically (any beginning text on
probabilities will have that very example).

Claudio Puviani


" osmium" < R 1 ******** @ comcast.net>在留言中写道

news:c5 *********** @ ID-179017.news.uni-berlin.de
"osmium" <r1********@comcast.net> wrote in message
news:c5***********@ID-179017.news.uni-berlin.de

鉴于一个房间里有无数人。
第一个人不会与任何人相匹敌。下一个人将有一个
*不同*生日,概率为364/365。下一个363/365。
等等。

Given a bazillion people in a room.
The fist person will not match anyone. The next person will have a
*different* birthday with probability 364/365. The next 363/365. And
so on.



正确回答错误的问题。


-

John卡森

1.要回复电子邮件地址,请删除donald

2.不要回复电子邮件地址(在此处发帖)


Right answer to the wrong question.

--
John Carson
1. To reply to email address, remove donald
2. Don''t reply to email address (post here instead)


这篇关于生日问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆