Re: [情報]2014年年度NBA推特人物-Manu Ginobili

作者: pponywong (pony)   2014-04-11 13:31:33
前面討論都刪掉
我原本以為也是 1/2 只好自己寫一個程式去跑
答案是 2/3
恭喜答對的人 =.=
底下是程式碼 有興趣的可以跑跑看
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define BLACK 0
#define SILVER 1
typedef struct card_s
{
int faces[2];
} card_t;
card_t cards[] =
{
{ SILVER, BLACK },
{ SILVER, SILVER },
};
int main(int argc, char** argv)
{
int i, idx, face_idx;
int count, total_count;
srand(time(NULL));
count = 0;
total_count = 0;
while(total_count < 100000)
{
idx = rand() & 0x1;
face_idx = rand() & 0x1;
if(cards[idx].faces[face_idx] == SILVER)
{
// check wether other side of face is SILVER or BLACK
if(cards[idx].faces[(face_idx + 1) & 0x1] == SILVER)
{
count++;
}
total_count++;
}
}
printf("P = %f\n", (float)count / (float)total_count);
return 0;
}
作者: skevin830126 (斷頭呆明)   2014-04-11 14:00:00
....商管給推
作者: homechen1990 (包溫)   2014-04-11 14:05:00
我來錯版了嗎

Links booklink

Contact Us: admin [ a t ] ucptt.com