------ 文章開始 ------

* 定義下面的集合允許重複的元素,索引由0開始,另外
  使用交集(∩)、聯集(∪)結果不包含重複元素。

* 定義二個集合的比對函數,取得a數量和b數量的結果。

    {count_a, count_b} := guestResult(s1, s2)

* 代入的例子:

    s1 = {2,6,5,2}
    s2 = {2,3,5,1}

* 以下為guestResult函數的運算步驟

1. 取交集

   定義s1、s2的交集結果 

       int = s1 ∩ s2 = {2, 5}
       ^ (intersection)

2. 反查位置

   定義 table(i, s) 為查詢 int[i] 在 s 中其索引的集合 

   table(0, s1) = {0, 3}
   table(0, s2) = {0}
   table(1, s1) = {2}
   table(1, s2) = {2}
   table(2, s1) = null
   table(2, s2) = null
   table(3, s1) = null
   table(3, s2) = null

3. 統計ab

   定義 count_a(i) = #(table(i, s1) ∩ table(i, s2))
   定義 count_b(i) = max{#table(i, s1), #table(i, s2)} - count_a(i)

   =>  count_a = count_a(0) + count_a(1) + ... + count_a(3)
       count_b = count_b(0) + count_b(1) + ... + count_b(3)

       PS: 排除null相加

   count_a(0) = #{0} = 1
   count_a(1) = #{2} = 1
   count_a(2) = #null = null
   count_a(3) = #null = null
   
   count_b(0) = max{#{0, 3}, #{0}} - 1 = max{2, 1} - 1 = 2 - 1 = 1
   count_b(1) = max{#{2}, #{2}} - 1 = max{1, 1} - 1 = 1 - 1 = 0
   count_b(2) = max{#null, #null} - null = null
   count_b(3) = max{#null, #null} - null = null

   count_a = 1 + 1 = 2
   count_b = 1 + 0 = 1

~~the end~~ By s3748679
------ 文章結尾 ------

[複製網址] [開新視窗] [檢舉短網址] [QR條碼]

服務條款 - 加入會員(免費) - 回報問題網址 - 聯絡偶們 -

© 2024 PPT.cc