假设桌子面积为area_t,扑克总面积为area_p,那么uniformly toss a point, the probability that the point falls into poker area is prob = area_p/area_t since you know area_t, you only need to compute prob, which is done using Monte Carlo simulation. basically, you randomly toss a point and decide whether or not it falls onto any of the 52 cards (this is done using O(1) time), then prob = # yes / # total tests
【在 m****r 的大作中提到】 : 如何 用 Monte Carlo simulation 来做呢 ? : 能具体说说吗 ? : 谢谢
r*n
15 楼
nice we can think of putting cards on a table one at time as an ergodic stochastic process. the time average converges to the expectation when # of cards, say m, is sufficiently large. this means b*[1 - (1 - a/b)^m] -> b as m -> infinite this makes sense since the total area is fixed
About "you randomly toss a point and decide whether or not it falls onto any of the 52 cards" The cards can overlap partially. How to handle this case ? Any help would be appreciated !
onto
【在 r*********n 的大作中提到】 : 假设桌子面积为area_t,扑克总面积为area_p,那么uniformly toss a point, the : probability that the point falls into poker area is : prob = area_p/area_t : since you know area_t, you only need to compute prob, which is done using : Monte Carlo simulation. : basically, you randomly toss a point and decide whether or not it falls onto : any of the 52 cards (this is done using O(1) time), then : prob = # yes / # total tests
r*n
17 楼
you know the center and the orientation (assuming card is rectangle) for each card to test whether a point falls onto a particular card is equivalent to test whether a 2D point is within a rectangle. one way to do this is to write down the line equations for all sides in the form f(X,Y) = aX + bY + c = 0... and check f_1(x, y)*f_2(x, y) <= 0 && f_3(x, y)*f_4(x, y) <= 0 here f_1 and f_2 denote the line equations of parallel sides and similarly f _3, f_4. f_1(x, y)*f_2(x, y) <= 0 means point (x,y) is between the two parallel sides. you can use the above method repetitively for all 52 cards, irrespective of how they overlap. and output true if one of the tests returns true. ps: there may be better ways to test whether a 2D point is within a rectangle.
any
【在 m****r 的大作中提到】 : About "you randomly toss a point and decide whether or not it falls onto any : of the 52 cards" : The cards can overlap partially. : How to handle this case ? : Any help would be appreciated ! : : onto
【在 J**9 的大作中提到】 : a1 = area of one card : a52 = a1*52 : return a random number from (a1..a52) : All numbers are double. : :-)
i*1
26 楼
赞,简洁,明了。
onto
【在 r*********n 的大作中提到】 : 假设桌子面积为area_t,扑克总面积为area_p,那么uniformly toss a point, the : probability that the point falls into poker area is : prob = area_p/area_t : since you know area_t, you only need to compute prob, which is done using : Monte Carlo simulation. : basically, you randomly toss a point and decide whether or not it falls onto : any of the 52 cards (this is done using O(1) time), then : prob = # yes / # total tests