Re: [問題] 未排序的陣列,演算法相關問題
# form y hash of array
# key -> value of y array
# value -> array of y indexes which point to the associative value
$idx = 0;
for $item (@y) {
push @{ $y_hash_of_arr{$item} }, $idx++; # push $idx into
} # y_hash_of_arr
$idx = 0;
for $item (@x) {
push @{ $inter_of_x{$item} }, $idx if exists $y_hash_of_arr{$num-$item};
$idx++;
}
@i = values %inter_of_x;
for $item (keys %inter_of_x){
push @yvalues, $num-$item;
}
@j = @y_hash_of_arr{@yvalues};
# inter_of_x 是只找出 x array 中符合 $num-$item 的雜湊
# 其鍵為 $item (就是 x array 的 value)
# 其值為 array of idx ,使用陣列是因為可能有多個idx含有同個值
#
# 根據inter_of_x可得到符合要求的yvalue
# 再由yvalue找到arr of idx of y
===============================
原始題目只要exists就好
@Hoy(@y)=(); # 只要鍵不用值
for (@x) { print "exists" and last if exists $Hoy{$num-$_}; }
這樣的話只會印出 "exists" 一次就會跳出迴圈了XD
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.136.177.207
→
05/10 08:27, , 1F
05/10 08:27, 1F
→
05/10 08:27, , 2F
05/10 08:27, 2F
→
05/10 11:50, , 3F
05/10 11:50, 3F
→
05/10 11:51, , 4F
05/10 11:51, 4F
→
05/10 12:10, , 5F
05/10 12:10, 5F
→
05/10 12:10, , 6F
05/10 12:10, 6F
→
05/10 12:11, , 7F
05/10 12:11, 7F
→
05/10 12:11, , 8F
05/10 12:11, 8F
→
05/10 12:12, , 9F
05/10 12:12, 9F
→
05/10 12:12, , 10F
05/10 12:12, 10F
→
05/10 12:14, , 11F
05/10 12:14, 11F
→
05/10 13:06, , 12F
05/10 13:06, 12F
※ 編輯: dryman 來自: 140.112.46.31 (05/10 13:28)
→
05/10 13:28, , 13F
05/10 13:28, 13F
→
05/10 13:29, , 14F
05/10 13:29, 14F
→
05/10 13:30, , 15F
05/10 13:30, 15F
→
05/10 13:31, , 16F
05/10 13:31, 16F
→
05/10 13:32, , 17F
05/10 13:32, 17F
→
05/10 13:32, , 18F
05/10 13:32, 18F
→
05/10 13:33, , 19F
05/10 13:33, 19F
→
05/10 13:36, , 20F
05/10 13:36, 20F
推
05/17 11:26, , 21F
05/17 11:26, 21F
→
05/17 11:26, , 22F
05/17 11:26, 22F
→
05/17 11:26, , 23F
05/17 11:26, 23F
→
05/17 11:27, , 24F
05/17 11:27, 24F
→
05/17 17:35, , 25F
05/17 17:35, 25F
→
05/18 08:07, , 26F
05/18 08:07, 26F
→
05/18 08:08, , 27F
05/18 08:08, 27F
→
05/18 08:08, , 28F
05/18 08:08, 28F
→
05/18 08:09, , 29F
05/18 08:09, 29F
→
05/18 08:10, , 30F
05/18 08:10, 30F
→
05/18 08:10, , 31F
05/18 08:10, 31F
→
05/18 08:11, , 32F
05/18 08:11, 32F
→
05/18 08:11, , 33F
05/18 08:11, 33F
→
05/18 08:12, , 34F
05/18 08:12, 34F
→
05/18 08:12, , 35F
05/18 08:12, 35F
→
05/18 08:13, , 36F
05/18 08:13, 36F
→
05/18 08:14, , 37F
05/18 08:14, 37F
→
05/18 08:16, , 38F
05/18 08:16, 38F
→
05/18 08:16, , 39F
05/18 08:16, 39F
→
05/18 08:19, , 40F
05/18 08:19, 40F
→
05/18 08:19, , 41F
05/18 08:19, 41F
→
05/18 08:19, , 42F
05/18 08:19, 42F
→
05/18 10:09, , 43F
05/18 10:09, 43F
→
05/18 10:09, , 44F
05/18 10:09, 44F
→
05/18 10:10, , 45F
05/18 10:10, 45F
推
05/18 14:39, , 46F
05/18 14:39, 46F
→
05/18 14:40, , 47F
05/18 14:40, 47F
※ 編輯: dryman 來自: 140.112.46.31 (05/18 22:10)
討論串 (同標題文章)
完整討論串 (本文為第 10 之 13 篇):
CSSE 近期熱門文章
PTT數位生活區 即時熱門文章