12
返回列表 发新帖
楼主: johnwan
跳转到指定楼层
上一主题 下一主题
收起左侧

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

🔗
ahbbzpc 2013-3-29 08:27:57 | 只看该作者
全局:
reeeelan 发表于 2013-3-28 06:32
有点我不是很明白,在N=9(1001)的时候,为什么大数是10(1010)而不是12(1100)?小数为什么是5(0101) ...

这题目是让找与a的1一样多的“最近”的大数和小数,也就是在1一样多的情况下找最小的大于a的数和最大的小于a的数
回复

使用道具 举报

🔗
ahbbzpc 2013-3-29 08:31:59 | 只看该作者
全局:
本帖最后由 ahbbzpc 于 2013-3-29 10:10 编辑

next largest number:
find lowest consecutive 0 and 1 , then exchange them.
next smallest number:
find lowest consecutive 1 and 0, then exchange them.
https://gist.github.com/ahbbzpc/b6495b0c301b35076554
参考了下前面那位同学的稍微改下

回复

使用道具 举报

🔗
ahbbzpc 2013-3-29 09:03:45 | 只看该作者
全局:
本帖最后由 ahbbzpc 于 2013-3-29 09:07 编辑
天道酬勤 发表于 2013-3-27 14:48
https://gist.github.com/Jnight/5252255 用我的代码跑一下就知道了..求测试,找到过不了的数据有加分

这个只能用在当前位数够的情况下,像7(111)就不行(虽然7没有nextsmall不过有nextlarge),而且万一像6一样(110)也没办法,个人感觉应该在最高位前面加一位置为0,当然是在不超过int范围的情况下。
回复

使用道具 举报

🔗
ThunderXu 2013-3-30 18:13:35 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5276198
treat the binary presentation as a string
Largest: find the rightest "01" and replace them, then make the part right of the position it smallest(put all 1s to the rightmost)
Smallest: Reverse of Largest
回复

使用道具 举报

🔗
ThunderXu 2013-3-30 18:18:49 | 只看该作者
全局:
ahbbzpc 发表于 2013-3-29 08:31
next largest number:
find lowest consecutive 0 and 1 , then exchange them.
next smallest number:
...

The next smallest number of 17(10001) should be 12(01100), but it will be 9(01001) according to your code
回复

使用道具 举报

🔗
ahbbzpc 2013-4-1 14:36:08 | 只看该作者
全局:
ThunderXu 发表于 2013-3-30 18:18
The next smallest number of 17(10001) should be 12(01100), but it will be 9(01001) according to yo ...

谢谢提醒..最高位为1的还真忘了考虑了
回复

使用道具 举报

🔗
麻倉枼 2013-5-26 09:05:33 | 只看该作者
全局:
一个问题,假如一个最高bit是32bit而那位置是1的话要怎么找next largest?
假设有这么一个数字,它的bit是:
1111 1111 1111。。。。。。1110
|_______ 32 bits ____________|

它的next largest 和 next smallest是什么?
回复

使用道具 举报

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

本版积分规则

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