大布丁
12 years ago
smallredbean: https://facebook.intervi... Thought you might be interested in. If you already know this just ignore it :-P
latest #33
Beany H.
12 years ago
I tried this before. I got an NP question. Damn i didn't even try to solve that...
大布丁
12 years ago
I guess this is a good reminder (tongue)
Beany H.
12 years ago
of ?
立即下載
大布丁
12 years ago
of the problem that's waiting for you!
Beany H.
12 years ago
dapudding > < no~~~ no NP questions
Beany H.
12 years ago
dapudding here's one for you. It's easy and you may also think about how you explain why your algo is correct
Beany H.
12 years ago
Given a sorted list of numbers
Beany H.
12 years ago
find two numbers a and b among them, that a-b=k given some k
Beany H.
12 years ago
there's an O(n) solution
Beany H.
12 years ago
e.g., 1 2 4 6 11 13 17 20
Beany H.
12 years ago
k = 6
Beany H.
12 years ago
then a = 11 and b = 17
Beany H.
12 years ago
Have fun & good night :-P
大布丁
12 years ago
..........orz
大布丁
12 years ago
i only came up with O(n^2) one: start with the numbers next to each other and check their difference. Then check the numbers that with one number between them, and two numbers between them and so on....
大布丁
12 years ago
wait...the complexity should be n! .....? God I suck at analyze this
Beany H.
12 years ago
dapudding: it's a "sorted" list ;-)
Beany H.
12 years ago
n^2 吧. n! 就直接掛電話了:-P
大布丁
12 years ago
幹嘛這樣QQ 為什麼不是n! ? 第一次scan跑n-1個element...第二次只要n-2個阿...最後一次不是只要看第一個跟最後一個差多少嗎QQ 就我的解法來說
大布丁
12 years ago
是說 我知道兩個數中間相差只要超過k就可以不用看了...但還想不到怎麼可以利用這點...拆成小的list?
Beany H.
12 years ago
n-1 + n-2 + n-3 + ... 2 + 1 =???
大布丁
12 years ago
阿 好啦QQ我懂了 大歐大歐
大布丁
12 years ago
欸幹 我是智障欸 好想把對話刪掉喔 n!明明就是階乘......
大布丁
12 years ago
不玩了 我要去麥當勞打工
Beany H.
12 years ago
a b ... c d ... <- the sorted list
known a<b<c<d
if c-a<k while d-a >k
do I have to check if c-b==k???
大布丁
12 years ago
來不及了我人已經在麥當勞哭了
大布丁
12 years ago
int ptr_a=0;
int ptr_b=1;
大布丁
12 years ago
while(ptr_b < list.length){
int diff = list[ptr_a] - list[ptr_b];
if(diff == k)
printf("a= %d, b= %d", list[ptr_a], list[ptr_b]);
else if(diff > k) ptr_a=ptr_b-1 else ptr_b +=1 }
大布丁
12 years ago
小豆你有沒有覺得你很適合當老師?其實你超有耐心的XD
大布丁
12 years ago
阿沒取絕對值
Beany H.
12 years ago
dapudding: 我只教聰明的孩子 (grin) 話說有大薯嗎?(hungry)
Beany H.
12 years ago
方向對了,但我還要仔細看看
大布丁
12 years ago
只要大薯就可以請的老師也是挺划算的XDDDDDDDD
back to top