關於前兩天那個最大期望值的問題

來源: 餅幹也需要愛啊 2009-02-20 21:58:16 [] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (1124 bytes)
原帖:http://web.wenxuecity.com/BBSView.php?SubID=computer&MsgID=160243
下麵是我寫的一個perl程序.這個程序不會直接給出最優解,而是僅僅幫你驗證你給出的組合的期望值.有興趣的朋友可以自己試試:
#!/usr/bin/perl -w

my @arr1 = split(/,/, $ARGV[0]);
my @arr2 = split(/,/, $ARGV[1]);

my $total = 0;
my $testsize = 100000;

for (my $count = 0; $count < $testsize ; $count++) {
shuffle(@arr1);
#print join(',',@arr1),' - ', join(',',@arr2),' => ';
my $sum = 0;
for (my $i=0;$i<6;$i++) {
$sum += $arr1[$i] * $arr2[$i];
}
#print "sum=$sum\n";
$total += $sum;
}

print 'average=',$total/$testsize;


print "\n";

exit;

sub shuffle {
my $len = @_;
for (my $i = 0; $i < $len; $i++) {
my $b=int(rand($len));
($_[$i],$_[$b])=($_[$b],$_[$i]);
}
}

#### end of program
如何使用:把上麵的代碼存為一個文本文件:card.pl,然後在命令行輸入:
perl card.pl 1,2,3,4,5,6,7 8,9,10,11,12,13
如你所見,程序接受兩個參數,分別以逗號分割的兩垛牌.你可以自己調節輸入你想試的組合.我目前找到的最大可能的期望值是337左右;-)

所有跟帖: 

book 11~~~ -奉旨泡妞- 給 奉旨泡妞 發送悄悄話 奉旨泡妞 的博客首頁 (0 bytes) () 02/20/2009 postreply 22:59:45

不好意思,有個錯誤要更正一下 -餅幹也需要愛啊- 給 餅幹也需要愛啊 發送悄悄話 (225 bytes) () 02/21/2009 postreply 21:45:01

好,多謝!你求出的最大期望值對應的大牌是怎麽分攤的? -IIIX- 給 IIIX 發送悄悄話 IIIX 的博客首頁 (0 bytes) () 02/22/2009 postreply 05:27:05

回複:好,多謝!你求出的最大期望值對應的大牌是怎麽分攤的? -餅幹也需要愛啊- 給 餅幹也需要愛啊 發送悄悄話 (14 bytes) () 02/22/2009 postreply 19:33:21

請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”