📣 独立日限时特惠: VIP通行证立减$68
查看: 1908| 回复: 7
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] [第二轮] 3/25-3/31 CareerCup 5.7

全局:

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

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

x
An array A contains all the integers from 0 to n, except for one number which is missing. In this problem, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is "fetch the jth bit of A[i]," which takes constant time. Write code to find the missing integer. Can you do it in O(n) time?

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

上一篇:[第二轮] 3/25-3/31 CareerCup 5.6
下一篇:[第二轮] 3/25-3/31 CareerCup 5.8
🔗
天道酬勤 2013-3-28 17:10:37 | 只看该作者
全局:
本帖最后由 天道酬勤 于 2013-3-29 09:08 编辑

/**
*  the number n is missing
*  count the bit one's number and bit zero's in the last bit of n, then judge second last bit of n, go on
*  why to judge the last bit to n?
*  As we know, 0,1,2,3,4...N: their last bit is 0 1 0 1 0 1;If there is a even missing num,
*  then the number of bit zero<=bit one; If a odd num is missed, then the bitzero>bit one.
*  By comparing the bit zero and bit one's count, we could know the last bit of the missing num.
*/
*/https://gist.github.com/Jnight/5261813 求测试,有加分
回复

使用道具 举报

🔗
PI2e 2013-3-28 23:33:39 | 只看该作者
全局:
天道酬勤 发表于 2013-3-28 17:10
/**
*  divide and conquer
*  the number n is missing

题里面没有说数组是排好序的吧

评分

参与人数 1大米 +3 收起 理由
天道酬勤 + 3 表述已经换了

查看全部评分

回复

使用道具 举报

🔗
menmen911 2013-3-29 10:03:01 | 只看该作者
全局:
默默的说个方法
全加起来,差哪个值不就看出来了?
回复

使用道具 举报

🔗
ahbbzpc 2013-3-29 10:16:47 | 只看该作者
全局:
menmen911 发表于 2013-3-29 10:03
默默的说个方法
全加起来,差哪个值不就看出来了?

In this problem, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is "fetch the jth bit of A," which takes constant time. Write code to find the missing integer. 审题仔细啊同学 要求是O(n) time
回复

使用道具 举报

🔗
reeeelan 2013-3-29 13:55:02 | 只看该作者
全局:
也就是说,所有数字都是按10111100 这样排下来? 中间有标点符号?
回复

使用道具 举报

全局:
* method: 位操作无能。。。。。感觉对自己智力已经没勇气直视了。。。。和编程珠玑上面一道题比较类似
https://gist.github.com/xuyirio/3156330
回复

使用道具 举报

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

本版积分规则

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