关于直觉

今天又见到这个智力问题了:

假设你参加了一个游戏节目,现在要从三个密封的箱子中选择一个。其中两个箱子是空的,另一个箱子里面有大奖(你偶像的签名^^)。你并不知道奖在哪一个箱 子里,但主持人知道。游戏节目的主持人先要你选择一个箱子,接着他把你没有选的空箱子打开,以证明它是空的。最后主持人给你换箱子的机会,你可以把你所选 择的箱子换成另一个没有打开的箱子。此时你该不该换箱子?

我的直觉告诉我,换与不换概率都是1/2.因为没有选择的那两个箱子里必定至少有一个是空的,这是个确定事件,所以,无论是否把它纠出来,对我的选择的 正确率都是没有影响的.而主持人指出那个空箱子的过程,那个箱子是正确的概率就应该平均分布到剩下的两个箱子中去了--概率他老人家应该是公平的吧,大概 不会偏向某一个箱子吧:)

回答这个问题的大致分为两派,一派选换,一派选不换(废话嘛,就俩答案...),我对自己的答案颇有信心,但在说服不同意见者方面没有多少信心--大家也知道,网上争吵一般是不会出现什么结果的,于是就写了段代码,让程序说话:

ContractedBlock.gifExpandedBlockStart.gifProgram.cs
None.gifusing System;
None.gif
None.gif
namespace SureNoChange
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
class Program
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
static void Main(string[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int timesToTry = 100000;
InBlock.gif
InBlock.gif            
int winsWithChange = SimulateChange(timesToTry);
InBlock.gif            Console.WriteLine(
"Wins after change decision: {0}/{1}", winsWithChange, timesToTry);
InBlock.gif
InBlock.gif            
int winsWithOutChange = SimulateNoChange(timesToTry);
InBlock.gif            Console.WriteLine(
"Wins without change decision: {0}/{1}", winsWithOutChange, timesToTry);
InBlock.gif
InBlock.gif            Console.ReadKey();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private static int SimulateChange(int timesToTry)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int timesWin = 0;
InBlock.gif            
for (int i = 0; i < timesToTry; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Game game 
= new Game();
InBlock.gif                game.PlayerSelectAnOption();
InBlock.gif                game.RemoveOneWrongOption();
InBlock.gif                game.ChangeChoice();
InBlock.gif
InBlock.gif                
if (game.Win)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    timesWin
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return timesWin;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private static int SimulateNoChange(int timesToTry)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int timesWin = 0;
InBlock.gif
InBlock.gif            
for (int i = 0; i < timesToTry; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Game game 
= new Game();
InBlock.gif                game.PlayerSelectAnOption();
InBlock.gif                game.RemoveOneWrongOption();
InBlock.gif                
if (game.Win)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    timesWin
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return timesWin;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
ContractedBlock.gifExpandedBlockStart.gifGame.cs
None.gifusing System;
None.gif
using System.Collections.Generic;
None.gif
None.gif
namespace SureNoChange
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
class Game
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        Random r;
InBlock.gif        Choice prize;
InBlock.gif        Choice choice;
InBlock.gif        Choice open;
InBlock.gif
InBlock.gif        
public Game()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            r 
= new Random();
InBlock.gif            prize 
= GetRandomChoice();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 玩家随机选择一个箱子
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        internal void PlayerSelectAnOption()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            choice 
= GetRandomChoice();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 从未被选择的,不是答案的箱子里打开一个
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        internal void RemoveOneWrongOption()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            List
<Choice> openable = new List<Choice>();
InBlock.gif            openable.AddRange(AllChoices);
InBlock.gif
InBlock.gif            openable.Remove(choice);
InBlock.gif            openable.Remove(prize);
InBlock.gif
InBlock.gif            open 
= openable[r.Next(openable.Count)];
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private Choice GetRandomChoice()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return AllChoices[r.Next(3)];
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 从先前选择的,打开的箱子以外的所有箱子里再随机选择一个
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        internal void ChangeChoice()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            List
<Choice> rest = new List<Choice>();
InBlock.gif            rest.AddRange(AllChoices);
InBlock.gif
InBlock.gif            rest.Remove(open);
InBlock.gif            rest.Remove(choice);
InBlock.gif
InBlock.gif            Choice newChoice 
= rest[r.Next(rest.Count)];
InBlock.gif            choice 
= newChoice;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
internal bool Win
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return choice == prize;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
static List<Choice> allChoices;
InBlock.gif        
static List<Choice> AllChoices
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (allChoices == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    allChoices 
= new List<Choice>();
InBlock.gif                    allChoices.AddRange((Choice[])Enum.GetValues(
typeof(Choice)));
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return allChoices;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
ContractedBlock.gifExpandedBlockStart.gifChoice.cs
None.gifnamespace SureNoChange
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
enum Choice
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        A,
InBlock.gif        B,
InBlock.gif        C,
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif


但是,结果却是:

Wins after change decision: 66924/100000
Wins without change decision: 
35009/100000

晕了,我的直觉居然错了!更改选择的话,得到奖品的可能性是2/3,不改的话,是1/3!

如果对这个宏观的"概率坍缩"的直觉都能犯这么大的错误,那些搞量子物理的,一再被实验结果打击,岂不会疯掉...
资源下载链接为: https://pan.quark.cn/s/d9ef5828b597 在本文中,我们将探讨如何通过 Vue.js 实现一个带有动画效果的“回到顶部”功能。Vue.js 是一款用于构建用户界面的流行 JavaScript 框架,其组件化和响应式设计让实现这种交互功能变得十分便捷。 首先,我们来分析 HTML 代码。在这个示例中,存在一个 ID 为 back-to-top 的 div 元素,其中包含两个 span 标签,分别显示“回到”和“顶部”文字。该 div 元素绑定了 Vue.js 的 @click 事件处理器 backToTop,用于处理点击事件,同时还绑定了 v-show 指令来控制按钮的显示与隐藏。v-cloak 指令的作用是在 Vue 实例渲染完成之前隐藏该元素,避免出现闪烁现象。 CSS 部分(backTop.css)主要负责样式设计。它首先清除了一些默认的边距和填充,对 html 和 body 进行了全屏布局,并设置了相对定位。.back-to-top 类则定义了“回到顶部”按钮的样式,包括其位置、圆角、阴影、填充以及悬停时背景颜色的变化。此外,与 v-cloak 相关的 CSS 确保在 Vue 实例加载过程中隐藏该元素。每个 .page 类代表一个页面,每个页面的高度设置为 400px,用于模拟多页面的滚动效果。 接下来是 JavaScript 部分(backTop.js)。在这,我们创建了一个 Vue 实例。实例的 el 属性指定 Vue 将挂载到的 DOM 元素(#back-to-top)。data 对象中包含三个属性:backTopShow 用于控制按钮的显示状态;backTopAllow 用于防止用户快速连续点击;backSeconds 定义了回到顶部所需的时间;showPx 则规定了滚动多少像素后显示“回到顶部”按钮。 在 V
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值