<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 最小乘積對為正整數數組 > 原文: [https://www.geeksforgeeks.org/minimum-product-pair-an-array-of-positive-integers/](https://www.geeksforgeeks.org/minimum-product-pair-an-array-of-positive-integers/) 給定一個正整數數組。 我們需要編寫一個程序來打印給定數組的任何兩個數字的最小乘積。 例子: ``` Input : 11 8 5 7 5 100 Output : 25 Explanation : The minimum product of any two numbers will be 5 * 5 = 25. Input : 198 76 544 123 154 675 Output : 7448 Explanation : The minimum product of any two numbers will be 76 * 123 = 7448. ``` **簡單方法**:一種簡單方法是運行兩個嵌套循環以生成所有可能的一對元素并跟蹤最小乘積。 時間復雜度:O(n * n) 輔助空間:`O(1)` **更好的方法**:一種有效的方法是首先對給定的數組排序并打印前兩個數字的乘積,排序將花費`O(N log N)`。 答案將是 a [0] * a [1] 時間復雜度:O(n * log(n)) 輔助空間:`O(1)` **最佳方法**:該想法是線性遍歷給定數組并跟蹤最少兩個元素。 最后返回兩個最小元素的乘積。 下面是上述方法的實現。 ## C++ ```cpp // C++ program to calculate minimum // product of a pair #include <bits/stdc++.h> using namespace std; // Function to calculate minimum product // of pair int printMinimumProduct(int arr[], int n) { ????// Initialize first and second ????// minimums. It is assumed that the ????// array has at least two elements. ????int first_min = min(arr[0], arr[1]); ????int second_min = max(arr[0], arr[1]); ????// Traverse remaining array and keep ????// track of two minimum elements (Note ????// that the two minimum elements may ????// be same if minimum element appears ????// more than once) ????// more than once) ????for (int i=2; i<n; i++) ????{ ???????if (arr[i] < first_min) ???????{ ??????????second_min = first_min; ??????????first_min = arr[i]; ???????} ???????else if (arr[i] < second_min) ??????????second_min = arr[i]; ????} ????return first_min * second_min; } // Driver program to test above function int main() { ????int a[] = { 11, 8 , 5 , 7 , 5 , 100 }; ????int n = sizeof(a) / sizeof(a[0]); ????cout << printMinimumProduct(a,n); ????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>

                              哎呀哎呀视频在线观看