由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - shuffle card 算法
相关主题
how to shuffle a deck of cards?问一下shuffle card问题
Randomly shuffle decks of cardsGoogle电面面经 + onsite求祝福
求问一道数组shuffle的问题碰到不置可否的面试官怎么办?
数组Shuffle 那道题Amazon On-site ,kindle组有什么要特别注意的地方么?+前两轮电面面经
报个T家的电面据m家面经+求分析
Anyone knowing how to shuffle a deck of cards in Java?分享一道Yelp电面题
刚看了下shuffle算法。发现有个问题startup onsite求祝福 + 面经
海量数据用什么排序方法好card shuffle的算法我自己都想不出来
相关话题的讨论汇总
话题: random话题: shuffle话题: card话题: shuffling话题: numbers
进入JobHunting版参与讨论
1 (共1页)
w*****3
发帖数: 101
1
java
不准用
math.random()
j*****u
发帖数: 1133
2
FT,
让你自己写random函数?

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

r******d
发帖数: 308
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];
}
}
I**********s
发帖数: 34
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()

w*****3
发帖数: 101
5
这题是MS的onsite题,
我觉得random是必须的吧,
难道这题是压力测试?
E********a
发帖数: 124
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];

1 (共1页)
进入JobHunting版参与讨论
相关主题
card shuffle的算法我自己都想不出来报个T家的电面据
关于排列组合的题目的算法Anyone knowing how to shuffle a deck of cards in Java?
问道题刚看了下shuffle算法。发现有个问题
这题咋做啊?海量数据用什么排序方法好
how to shuffle a deck of cards?问一下shuffle card问题
Randomly shuffle decks of cardsGoogle电面面经 + onsite求祝福
求问一道数组shuffle的问题碰到不置可否的面试官怎么办?
数组Shuffle 那道题Amazon On-site ,kindle组有什么要特别注意的地方么?+前两轮电面面经
相关话题的讨论汇总
话题: random话题: shuffle话题: card话题: shuffling话题: numbers