【发布时间】:2017-05-05 23:52:54
【问题描述】:
我目前正在编写一个函数,它会询问您的牌组大小、该牌组中某张特定牌的副本数量、您的初始手牌规模、您调度的牌数量(我们正在设置调度的牌除了抽牌,然后将重新调度的牌洗回),以及你想在哪轮抽到那张牌。
本质上,我将不抽牌的所有概率相乘(然后用 1 减去该概率)来得出在特定回合中抽到特定牌的概率。到目前为止,我的函数如下所示:
void card_probability() {
int total;
int numCopies;
int n;
int m;
int turn;
double initial_draw_prob;
double mulligan_prob;
double draw_prob;
double neg_probability;
double probability;
printf("Enter how many total cards there are in the deck: ");
scanf("%d", &total);
printf("Enter how many copies of the card that you are looking for are
in the deck: ");
scanf("%d", &numCopies);
printf("Enter your initial hand size: ");
scanf("%d", &n);
printf("Enter how many cards you are mulliganing: ");
scanf("%d", &m);
printf("Enter what turn you want to draw the card by: ");
scanf("%d", &turn);
initial_draw_prob = ((total - numCopies) / total);
//for loop{}
mulligan_prob = ((total - numCopies - n) / (total - n));
//for loop{}
draw_prob = ((total - numCopies - n - m) / (total - n - m));
//for loop{}
neg_probability = initial_draw_prob * mulligan_prob * draw_prob;
probability = 1 - neg_probability
printf("The probability of drawing at least one of the cards by turn %d
given you mulliganed %d cards is %lf", turn, m, probability);
}
int main(){
card_probability();
return 0;
}
我在设置这些 for 循环以使其正常工作时遇到问题。基本上发生的是三个不同的概率部分:
1.) 在你的第一手牌中没有抽到想要的牌的概率 (total - numCopies) / (total) 是第一次抽牌时没有抽到那张牌的概率。然后,例如,如果您总共抽了 7 张牌,您将继续将概率相乘,直到得到 (total - numCopies - 7) / (total - 7) 项。
2.) 调度指定金额后不抽牌的概率。
3.) 在指定的回合没有抽到牌的概率。
谁能帮我设置这些 for 循环?我无法得到正确的增量。我在纸上进行了数学计算,牌组大小为 10,我想要 2 张牌,手牌大小为 2,调度 1,选择 3 轮,我有 16.66% 的几率不抽牌 =>大约 83% 的人在第 3 回合抽牌。
【问题讨论】:
-
为什么你的标题里是C语言,而你的标签里是C++?你用的是哪个?例如,如果您使用 C++,则应使用
std::string表示文本,使用std::vector而不是数组。 -
我正在使用 C。我已经编辑了标签。感谢您的关注!
-
更喜欢使用
fscanf而不是dangerousscanf。 -
@ThomasMatthews - 你的建议有缺陷。
fscanf()的安全性不亚于scanf()。造成这两种危险的因素与格式字符串和后续参数之间可能的不匹配有关,或者在读取字符串时缓冲区溢出(将多个字符读取到大小不足的缓冲区)。 -
你的论文计算是incorrect。
标签: c