由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问个careercup上的老题目,看不懂答案
相关主题
看programming pearl进行时的感想请教一道面试题
bit manipulation 小题Google 面试题 一道
菜鸟问个two sum的变型题请教一个DP的问题
问个google面试题来个bit题
G题一道(1)问题
Careercup question.One question on Careercup
a problem: find local maxima in sublinear timecareercup上这道题我竟然没看懂
一道面试题看不懂Ask a amazon question from careercup.
相关话题的讨论汇总
话题: number话题: neighbor话题: careercup话题: find
进入JobHunting版参与讨论
1 (共1页)
c*****y
发帖数: 90
1
Given a integer, output its previous and next neighbor number which has
the same number of bit 1 in their binary representation.
下面为什么去判断(number & 3) != 2?
while ((number & 3) != 2) { // for right neighbor, change this line to
// (number & 3) != 1
a**x
发帖数: 154
2
find the lowest 01 pattern and swap it to find the bigger neighbor number,
while find the lowest 10 pattern and swap it to find the smaller neighbor
number
c*****y
发帖数: 90
3
我开始也同意这个解法,可是发现有的例子用这个方法得不到正确答案。比如0101,按
理它的下一个同样多1的数是0110,可是按这个方法却是1001。另外为什么用那个&3?
我觉得应该是find the lowest 0 and lowest 1, swap them.

number,
neighbor

【在 a**x 的大作中提到】
: find the lowest 01 pattern and swap it to find the bigger neighbor number,
: while find the lowest 10 pattern and swap it to find the smaller neighbor
: number

g*******y
发帖数: 1930
4
swap 01 成为10还不够吧
比如
011100
如果swap第一个01,就成了101100
但是正确答案应该是 100011
其实呢,就是swap lowest 01后,应该对后面那截的数做一个简单的0,1排序(尽可能
把后面的所有1都扔到低位)

【在 a**x 的大作中提到】
: find the lowest 01 pattern and swap it to find the bigger neighbor number,
: while find the lowest 10 pattern and swap it to find the smaller neighbor
: number

b****j
发帖数: 78
5
这个也是错的,10会变成01。

【在 c*****y 的大作中提到】
: 我开始也同意这个解法,可是发现有的例子用这个方法得不到正确答案。比如0101,按
: 理它的下一个同样多1的数是0110,可是按这个方法却是1001。另外为什么用那个&3?
: 我觉得应该是find the lowest 0 and lowest 1, swap them.
:
: number,
: neighbor

z***e
发帖数: 5393
6
你在careercup上也这个id?

【在 g*******y 的大作中提到】
: swap 01 成为10还不够吧
: 比如
: 011100
: 如果swap第一个01,就成了101100
: 但是正确答案应该是 100011
: 其实呢,就是swap lowest 01后,应该对后面那截的数做一个简单的0,1排序(尽可能
: 把后面的所有1都扔到低位)

g*******y
发帖数: 1930
7
嗯,有时候也匿名。不过以前还认真回复一下,后来基本上就是偶尔去灌一下水玩玩了
。还是喜欢咱买买提待闺版,呵呵

【在 z***e 的大作中提到】
: 你在careercup上也这个id?
k***e
发帖数: 556
8
这道题有点复杂
1. are we focusing on unsigned integers now?
if so, then for (1)_2, (11)_2, (111)_2, we cannot find numbers smaller than
them with equal no of 1's.
2. are we focusing on signed integers?
if so, are we using the complementary representation, or we just count the
1's in abs(x)? how about overflow? anyway, it is messy.

【在 c*****y 的大作中提到】
: Given a integer, output its previous and next neighbor number which has
: the same number of bit 1 in their binary representation.
: 下面为什么去判断(number & 3) != 2?
: while ((number & 3) != 2) { // for right neighbor, change this line to
: // (number & 3) != 1

k***e
发帖数: 556
9
那里傻x老印太多
上次有道题要用suffix tree才能做,我就写了一下大概的方法
结果一个老印居然鄙视我 说应该写出code来
无语中

【在 g*******y 的大作中提到】
: 嗯,有时候也匿名。不过以前还认真回复一下,后来基本上就是偶尔去灌一下水玩玩了
: 。还是喜欢咱买买提待闺版,呵呵

1 (共1页)
进入JobHunting版参与讨论
相关主题
Ask a amazon question from careercup.G题一道(1)
问一道CareerCup里的题目Careercup question.
array a1,a2,... ,an, b1,b2,..., bna problem: find local maxima in sublinear time
careercup书上那个maintain median value的题一道面试题看不懂
看programming pearl进行时的感想请教一道面试题
bit manipulation 小题Google 面试题 一道
菜鸟问个two sum的变型题请教一个DP的问题
问个google面试题来个bit题
相关话题的讨论汇总
话题: number话题: neighbor话题: careercup话题: find