作者haryewkun (Har)
看板Programming
标题Re: [问题] 演算法
时间Tue Jan 16 02:25:52 2007
※ 引述《march20 ()》之铭言:
: ※ 引述《yaote (ted)》之铭言:
: : 标题: [问题] 演算法
: : 时间: Sat Jan 13 11:16:10 2007
: : 以下是一所国外研究所的考试题目,是否能用程式跟图解来解答这个问题?
: : I have a computer file containing 1,000,000 non-negative integers,
: : in no particular order. Imagine that they are the membership numbers of
: : people who are enrolled in my internet club. A new person wants to join
: : the club, and we need to find an unused number to allocate to them. How
: : would you find, in a reasonable time, a number that was not already in the
: : file?
: : --
: : ◆ From: 220.140.56.26
: : 推 march20:全部加起来一定没问题 XD 71.136.235.216 01/13 11:58
: : 推 march20:如果只需要一次的话. 71.136.235.216 01/13 11:59
: : 推 march20:不然长远来看, 用些资料结构来放会比较赚 71.136.235.216 01/13 11:59
: : 推 march20:喔, 为了避免 0 的问题, sum 完後再加1 71.136.235.216 01/13 12:07
: 马上发现其实我想太麻烦了 (虽然那也是第一时间想到的)
: 只要找到 max 再加一就好.
: max 根本就是一读完档就找到了
换题目玩玩。
如果我们不要走漏洞,而是真的当作是实用的情况,然後把题目修改一点,
必须要找出最小、而又没有被使用的数字,那麽除了排序之外,还有没有其
他更快捷的方法?
讨论区真的有这个问题。就是十万个用户,注册了从 1到100000的 UID,然
後版主删掉中间五万名会员,所以就零零散散地断层了。如果新用户注册,
就必须用 100001 的UID。
如果是这样的问题,除了排序之外,还有没有别的办法?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 60.50.36.148
1F:推 ephesians:不见得是排序,而是找空座位的问题218.160.212.119 01/16 16:35