Re: [閒聊] 1%的抽卡率抽100次機率是63.4%?
※ 引述《fragmentwing (片翼碎夢)》之銘言:
: 原本想說要用log去算,發現超不準,只好直接算了
: 怕超過2*32次,就用10次和0.1的機率去算了
: 至少一次的機率==一次+兩次+...+N(抽的總次數)次
: 以下程式碼,才正式學C不到10天,請鞭小力點
:
: #include<stdio.h>
: #include<math.h>
: int cntnis(int a,int b){
: int top=1,bottom=1;
: for(int i=1;i<=b;i++){
: top*=(a-i+1);
: bottom*=i;
: }
:
: int compute=top/bottom;
: return compute;
: }
:
: double multi(double have,int havet,int nohavet){
: double result=pow(have,havet)*pow((1.0-have),nohavet);
: return result;
: }
:
: int main(){
: int times,cntn,i;
: double haveis,mulh,probability,expectation=0;
:
: times=10;
: haveis=0.1;
:
: for(i=1;i<=times;i++){
: cntn=cntnis(times,i);
: mulh=multi(haveis,i,times-i);
: probability=cntn*mulh;
: printf("抽 %d 次中,抽中 %d 張的機率= %lf\n",times,i,probability);
: expectation+=probability*i;
: }
:
: printf("抽 %d 次,機率 %.3lf 期望值為: %lf",times,haveis,expectation);
:
: return 0;
: }
用Python的話,你的原程式碼按照原有邏輯可以改寫成下面這樣
----
import scipy.special
times = 10
haveis = .1
expectation = 0
for i in range(1,times+1):
probability = scipy.special.comb(times,i)*haveis**i*(1-haveis)**(times-i)
print("抽" +str(times) +"次中,抽中"+ str(i)+"張的機率="+ str(probability))
expectation += probability*i
print("抽"+str(times)+"次,機率 "+str(haveis)+" 期望值為"+str(expectation))
----
: → hinanaitenco: 這用matlab吧 06/03 23:41
我不太建議
MATLAB很貴,而且你一使用很容易變成MATLAB的禁臠
--
「ZZZZZ.....zzzzz.....」 ~中野二乃
https://i.imgur.com/kaUuF3R.jpg
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 71.198.27.180 (美國)
※ 文章網址: https://www.ptt.cc/bbs/C_Chat/M.1559585203.A.C97.html
→
06/04 02:07,
4年前
, 1F
06/04 02:07, 1F
是啊 所以理工大學有很多MATLAB的禁臠啊
→
06/04 02:09,
4年前
, 2F
06/04 02:09, 2F
→
06/04 02:10,
4年前
, 3F
06/04 02:10, 3F
我反而覺得MATLAB就是用起來太舒服才恐怖
→
06/04 02:12,
4年前
, 4F
06/04 02:12, 4F
推
06/04 02:12,
4年前
, 5F
06/04 02:12, 5F
學Python不難。難的是你要怎麼克制自己想要去用MATLAB
這有點像本本裡面女主變成男主的形狀之後,不管時隔多久,
只要再度見面,看到男主的O棒一樣X水直流
→
06/04 02:12,
4年前
, 6F
06/04 02:12, 6F
→
06/04 02:13,
4年前
, 7F
06/04 02:13, 7F
那個是Simulink。 MATLAB 的騙課神器
→
06/04 02:13,
4年前
, 8F
06/04 02:13, 8F
→
06/04 02:16,
4年前
, 9F
06/04 02:16, 9F
→
06/04 02:17,
4年前
, 10F
06/04 02:17, 10F
就很方便啊。其實也別說Simulink,光講繪圖library好了,
matplotlib 跟 MATLAB的繪圖函式庫和介面相比真的超難用
推
06/04 02:21,
4年前
, 11F
06/04 02:21, 11F
→
06/04 02:21,
4年前
, 12F
06/04 02:21, 12F
→
06/04 02:21,
4年前
, 13F
06/04 02:21, 13F
但Python不用錢啊。
MATLAB 一套只有基本函式庫+Simulink 就要 2150 USD了,
要持續更新的話你就要持續地繳交年費
→
06/04 02:23,
4年前
, 14F
06/04 02:23, 14F
→
06/04 02:25,
4年前
, 15F
06/04 02:25, 15F
→
06/04 02:25,
4年前
, 16F
06/04 02:25, 16F
→
06/04 02:26,
4年前
, 17F
06/04 02:26, 17F
→
06/04 02:26,
4年前
, 18F
06/04 02:26, 18F
→
06/04 02:27,
4年前
, 19F
06/04 02:27, 19F
→
06/04 02:27,
4年前
, 20F
06/04 02:27, 20F
推
06/04 02:35,
4年前
, 21F
06/04 02:35, 21F
推
06/04 02:36,
4年前
, 22F
06/04 02:36, 22F
推
06/04 03:50,
4年前
, 23F
06/04 03:50, 23F
※ 編輯: arrenwu (71.198.27.180 美國), 06/04/2019 07:15:19
推
06/04 07:36,
4年前
, 24F
06/04 07:36, 24F
推
06/04 08:33,
4年前
, 25F
06/04 08:33, 25F
→
06/04 08:33,
4年前
, 26F
06/04 08:33, 26F
→
06/04 11:47,
4年前
, 27F
06/04 11:47, 27F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 6 之 9 篇):