it takes a bit more than that

來源: dynamic 2009-05-18 19:55:29 [] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (438 bytes)
本文內容已被 [ dynamic ] 在 2009-06-09 09:31:02 編輯過。如有問題,請報告版主或論壇管理刪除.
回答: algorithmic complexity requirement?haha20002009-05-18 19:19:21
there are some issues with your method:

1. starting with a[i] != i, you might find a cycle and go back to i. In this cycle, no element occurred more than once.

2. The problem asks you to find one repeated element. Not every element in a cycle is repeated. Finding the exact "entrance" to a cycle is the tricky part of the problem.

The big idea is correct though, and there is a linear time algorithm. Good luck~

所有跟帖: 

hmm,這個有意思:) -戲雨飛鷹- 給 戲雨飛鷹 發送悄悄話 戲雨飛鷹 的博客首頁 (0 bytes) () 05/18/2009 postreply 21:12:19

回複:it takes a bit more than that -utopian- 給 utopian 發送悄悄話 (51 bytes) () 05/20/2009 postreply 17:23:11

hashing needs linear memory as well. we want constant memory her -dynamic- 給 dynamic 發送悄悄話 (0 bytes) () 05/20/2009 postreply 17:28:12

Pay attention to some key numbers. -亂彈- 給 亂彈 發送悄悄話 亂彈 的博客首頁 (0 bytes) () 05/20/2009 postreply 19:24:24

覺得在哪裏見過這個題目 -haha2000- 給 haha2000 發送悄悄話 (19 bytes) () 05/21/2009 postreply 07:24:10

I don't think so. -亂彈- 給 亂彈 發送悄悄話 亂彈 的博客首頁 (0 bytes) () 05/21/2009 postreply 09:52:29

這題目是IMB 2004 一月的一個puzzle:) -戲雨飛鷹- 給 戲雨飛鷹 發送悄悄話 戲雨飛鷹 的博客首頁 (79 bytes) () 05/21/2009 postreply 12:22:12

Yes, right! thanks! -haha2000- 給 haha2000 發送悄悄話 (0 bytes) () 05/22/2009 postreply 11:05:23

請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”