avatar
j*u
2
FT,
让你自己写random函数?

【在 w*****3 的大作中提到】
: java
: 不准用
: math.random()

avatar
r*d
3
不知道标准的shuffle card是什么算法
我每次洗牌都把牌分成两半, 然后左边一张, 右边一张地把牌混起来。
那用一个array放入所有的牌, 反复call一个洗牌的函数。 在那个函数里面把牌的前
面一半和后面一般间隔混起来?
void fun()
{
.....
for ( int i =1; i{
card_after[i]=card_before[i];
card_after[i+1]=card_before[i+n/2];
}
}
avatar
I*s
4
http://en.wikipedia.org/wiki/Shuffling
"Shuffling algorithms
In a computer, shuffling is equivalent to generating a random permutation of
the cards. There are two basic
algorithms for doing this, both popularized by Donald Knuth.
The first is simply to assign a random number to each card, and then to sort
the cards in order of their random
numbers. This will generate a random permutation, unless any of the random
numbers generated are the
same as any others (i.e. pairs, triplets etc). This can be eliminated either
assigning new random numbers to
these cases, or reduced to an arbitrarily low probability by choosing a
sufficiently wide range of random
number choices. If using efficient sorting such as mergesort or heapsort,
this is an O(n log n) algorithm.
The second, generally known as the Knuth shuffle or Fisher–Yates shuffle,
is a linear-time algorithm which
involves moving through the pack from top to bottom, swapping each card in
turn with another card from a
random position in the part of the pack that has not yet been passed through
(including itself). Providing that
the random numbers are unbiased, this will always generate a random
permutation."

【在 w*****3 的大作中提到】
: java
: 不准用
: math.random()

avatar
w*3
5
这题是MS的onsite题,
我觉得random是必须的吧,
难道这题是压力测试?
avatar
E*a
6

you are talking about perfect shuffling, like A1A2A3B1B2B3 A1B1A2B2A3B3
I guess lz talked about random shuffling

【在 r******d 的大作中提到】
: 不知道标准的shuffle card是什么算法
: 我每次洗牌都把牌分成两半, 然后左边一张, 右边一张地把牌混起来。
: 那用一个array放入所有的牌, 反复call一个洗牌的函数。 在那个函数里面把牌的前
: 面一半和后面一般间隔混起来?
: void fun()
: {
: .....
: for ( int i =1; i: {
: card_after[i]=card_before[i];

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。