查看: 1905| 回复: 9
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] [第二轮] 3/18-3/24 CareerCup 5.1

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to insert M into N such that M starts at bit j and ends at bit i. You can assume that the bits j through i have enough space to fit all of M. That is, if M=10011, you can assume that there are at least 5 bits between j and i. You would not, for example, have j = 3 and i=2, because M could not fully fit between bit 3 and bit 2.
EXAMPLE
Input: N = 10000000000, M = 10011, i = 2, j = 6
Output: N = 10001001100

发帖规范:
http://www.1point3acres.com/bbs/thread-48094-1-1.html
http://www.1point3acres.com/bbs/thread-32423-1-1.html

上一篇:[第二轮] 3/18-3/24 CareerCup 4.9
下一篇:[第二轮] 3/18-3/24 CareerCup 5.2
🔗
EchoMemory 2013-3-19 18:14:05 | 只看该作者
全局:
easy one...
回复

使用道具 举报

全局:
method:
*    1,  basic bit operation,one bit by one bit....
*    2 , the standard solution is better than me....
*            a, clear the bits from i to j in N
*            b, shift M so that it lines up with bits from i to j
*            c, merge the two num......
https://github.com/1094401996/Ca ... ot1/InsertBits.java

位操作很容易犯off one的错误。。。。。
回复

使用道具 举报

🔗
myisabella 2013-3-23 08:34:06 | 只看该作者
全局:
跟楼上思路基本一样,顺便用了个datalab里面的bitMask函数
https://gist.github.com/myisabella/5225785#file-problem_51-java
回复

使用道具 举报

🔗
ThunderXu 2013-3-24 15:19:56 | 只看该作者
全局:
https://gist.github.com/ThunderXu/426b45f7736287fe2aab
Set by bit, 规格严格理性帝's second method is much better
回复

使用道具 举报

🔗
grassgigi 2013-3-25 06:00:10 | 只看该作者
全局:
bit mask, same thoughts as method on book
https://gist.github.com/chrislukkk/5233720
回复

使用道具 举报

🔗
天道酬勤 2013-3-25 11:36:25 | 只看该作者
全局:
/**
* part1: convert "10000000000" into "10000xxxxxx", x is '0' produced by bit move
* part2: convert "10011" into "10011xx"
* part3: convert "10000000000" into "xxxxxxxxx00"
* answer is part1|part2|part3
* We use "Or" in this algorithm instead of "And" Why?
* Compared to convert "10011" into "0000000000000000000000000 10011 00" then use "Or" operation,
* it is inconvenient to convert "10011" into "111111111111111111111111111111 10011 11" then use "And" operation,
*
*/
https://gist.github.com/Jnight/5234702 求点评,有加分
回复

使用道具 举报

🔗
宋小宝Dani 2013-3-27 20:09:40 | 只看该作者
全局:
https://gist.github.com/5253713.git
same as the standard solution
回复

使用道具 举报

🔗
冰点 2014-1-26 10:25:32 | 只看该作者
全局:
这道题能否这样做:比如N=1000 0000, M=10011, i=2, j=6
step1:产生一个长为M的一串1
step2:将这一串1移到第i位,并和N进行位或操作,存为newN
step3:把M移到第i位,与newN进行位与,输出结果
这是我自己想的,请各路大神版主提出宝贵意见,不胜感激啊!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表