<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 隨機對為最大加權對的概率 > 原文: [https://www.geeksforgeeks.org/probability-random-pair-maximum-weighted-pair/](https://www.geeksforgeeks.org/probability-random-pair-maximum-weighted-pair/) 給定兩個數組 A 和 B,從數組 A 中選擇一個元素,數組 B 中另一個元素,從中選取一個隨機對。輸出該對被最大加權的概率。 **示例**: ``` Input : A[] = 1 2 3 B[] = 1 3 3 Output : 0.222 Explanation : Possible pairs are : {1, 1}, {1, 3}, {1, 3}, {2, 1}, {2, 3}, {2, 3}, {3, 1}, {3, 3}, {3, 3} i.e. 9. The pair with maximum weight is {3, 3} with frequency 2\. So, the probability of random pair being maximum is 2/9 = 0.2222. ``` **暴力法**:以 N ^ 2 的時間復雜度生成所有可能的對,并計算 最大加權對。 **更好的方法**:對兩個數組都進行排序,并對 A 和 B 中的最后一個(最大)元素進行計數。最大加權對的數量將是這兩個計數的乘積。 概率將為 (計數的乘積)/ sizeof(A)* sizeof(B) **最佳方法**最佳方法將是遍歷兩個數組并計算最大元素。 最大加權對的數量將是兩個計數的乘積。 概率將是(計數的乘積)/ sizeof(A)* sizeof(B) 下面是實現: ## C++ ```cpp #include <bits/stdc++.h> using namespace std; // Function to return probability double probability(int a[], int b[], int size1,? ?????????????????????????????????????int size2) { ????// Count occurrences of maximum element? ????// in A[] ????int max1 = INT_MIN,? count1 = 0; ????for (int i = 0; i < size1; i++) { ????????if (a[i] > max1) { ????????????max1 = a[i]; ????????????count1 = 1; ????????} ????????else if (a[i] == max1) { ????????????count1++; ????????} ????} ????// Count occurrences of maximum element? ????// in B[] ????int max2 = INT_MIN, count2 = 0; ????for (int i = 0; i < size2; i++) { ????????if (b[i] > max2) { ????????????max2 = b[i]; ????????????count2 = 1; ????????} ????????else if (b[i] == max2) { ????????????count2++; ????????} ????} ????// Returning probability ????return (double)(count1 * count2) /? ??????????????????(size1 * size2); } // Driver code int main() { ????int a[] = { 1, 2, 3 }; ????int b[] = { 1, 3, 3 }; ????int size1 = sizeof(a) / sizeof(a[0]); ????int size2 = sizeof(b) / sizeof(b[0]); ????cout << probability(a, b, size1, size2); ????return 0; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看