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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 第一個數組中的最大值與第二個數組中的最小值的乘積 > 原文: [https://www.geeksforgeeks.org/product-maximum-first-array-minimum-second/](https://www.geeksforgeeks.org/product-maximum-first-array-minimum-second/) 給定兩個數組,任務是計算第一個數組的 max 元素和第二個數組的 min 元素的乘積 參考文獻:在 Adobe 中提問(來源: [Careercup](https://www.careercup.com/question?id=5703822780399616) ) **示例**: ``` Input : arr1[] = {5, 7, 9, 3, 6, 2}, arr2[] = {1, 2, 6, -1, 0, 9} Output : max element in first array is 9 and min element in second array is -1\. The product of these two is -9. Input : arr1[] = {1, 4, 2, 3, 10, 2}, arr2[] = {4, 2, 6, 5, 2, 9} Output : max element in first array is 10 and min element in second array is 2\. The product of these two is 20. ``` **方法 1:簡單方法**我們首先對兩個數組進行排序。 然后,我們可以輕松地在第一個數組中找到 max,在第二個數組中找到 min。 最后,我們返回最小值和最大值的乘積。 ## C++ ```cpp // C++ program to calculate the // product of max element of // first array and min element // of second array #include <bits/stdc++.h> using namespace std; // Function to calculate // the product int minMaxProduct(int arr1[],? ??????????????????int arr2[],? ??????????????????int n1,? ??????????????????int n2) { ????// Sort the arrays to find? ????// the maximum and minimum? ????// elements in given arrays ????sort(arr1, arr1 + n1); ????sort(arr2, arr2 + n2); ????// Return product of ????// maximum and minimum. ????return arr1[n1 - 1] * arr2[0]; } // Driven code int main() { ????int arr1[] = { 10, 2, 3, 6, 4, 1 }; ????int arr2[] = { 5, 1, 4, 2, 6, 9 }; ????int n1 = sizeof(arr1) / sizeof(arr1[0]); ????int n2 = sizeof(arr1) / sizeof(arr1[0]); ????cout << minMaxProductt(arr1, arr2, n1, n2); ????return 0; } ``` ## Java ```java // Java program to find the? // to calculate the product? // of max element of first? // array and min element of? // second array import java.util.*; import java.lang.*; class GfG { ????// Function to calculate ????// the product ????public static int minMaxProduct(int arr1[], ????????????????????????????????????int arr2[],? ????????????????????????????????????int n1,? ????????????????????????????????????int n2) ????{ ????????// Sort the arrays to find the? ????????// maximum and minimum elements? ????????// in given arrays ????????Arrays.sort(arr1); ????????Arrays.sort(arr2); ????????// Return product of maximum ????????// and minimum. ????????return arr1[n1 - 1] * arr2[0]; ????} ????// Driver Code ????public static void main(String argc[]) ????{ ????????int [] arr1= new int []{ 10, 2, 3,? ??????????????????????????????????6, 4, 1 }; ????????int [] arr2 = new int []{ 5, 1, 4,? ??????????????????????????????????2, 6, 9 }; ????????int n1 = 6; ????????int n2 = 6; ????????System.out.println(minMaxProduct(arr1,? ?????????????????????????????????????????arr2,? ?????????????????????????????????????????n1, n2)); ????} } /*This code is contributed by Sagar Shukla.*/ ``` ## Python ``` # A Python program to find the to # calculate the product of max # element of first array and min # element of second array # Function to calculate the product def minmaxProduct(arr1, arr2, n1, n2): ????# Sort the arrays to find the? ????# maximum and minimum elements ????# in given arrays ????arr1.sort() ????arr2.sort() ????# Return product of maximum ????# and minimum. ????return arr1[n1 - 1] * arr2[0] # Driver Program arr1 = [10, 2, 3, 6, 4, 1] arr2 = [5, 1, 4, 2, 6, 9] n1 = len(arr1) n2 = len(arr2) print(minmaxProduct(arr1, arr2, n1, n2)) # This code is contributed by Shrikant13\. ``` ## C# ```cs // C# program to find the to? // calculate the product of? // max element of first array? // and min element of second array using System; class GfG { ????// Function to calculate the product ????public static int minMaxProduct(int []arr1,? ????????????????????????????????????int []arr2,? ????????????????????????????????????int n1,? ????????????????????????????????????int n2) ????{ ????????// Sort the arrays to find the? ????????// maximum and minimum elements? ????????// in given arrays ????????Array.Sort(arr1); ????????Array.Sort(arr2); ????????// Return product of maximum ????????// and minimum. ????????return arr1[n1 - 1] * arr2[0]; ????} ????// Driver Code ????public static void Main() ????{ ????????int [] arr1= new int []{ 10, 2, 3,? ?????????????????????????????????6, 4, 1 }; ????????int [] arr2 = new int []{ 5, 1, 4, ??????????????????????????????????2, 6, 9 }; ????????int n1 = 6; ????????int n2 = 6; ????????Console.WriteLine(minMaxProduct(arr1, arr2,? ????????????????????????????????????????n1, n2)); ????} } /*This code is contributed by vt_m.*/ ``` ## PHP ```php <?php // PHP program to find the to? // calculate the product of max // element of first array and // min element of second array // Function to calculate the product function minMaxProduct( $arr1, $arr2,? ????????????????????????$n1, $n2) { ????// Sort the arrays to find? ????// the maximum and minimum? ????// elements in given arrays ????sort($arr1); ????sort($arr2); ????// Return product of ????// maximum and minimum. ????return $arr1[$n1 - 1] * $arr2[0]; } // Driver code $arr1 = array( 10, 2, 3, 6, 4, 1 ); $arr2 = array( 5, 1, 4, 2, 6, 9 ); $n1 = count($arr1); $n2 = count($arr2); echo minMaxProduct($arr1, $arr2,? ???????????????????$n1, $n2); // This code is contributed by anuj_67\. ?> ``` **輸出**: ``` 10 ``` **時間復雜度**:`O(N log N)` **空間復雜度**:`O(1)` **方法 2:高效方法**在這種方法中,我們只需遍歷整個數組,然后在第一個數組中找到 max,在第二個數組中找到 min,就可以輕松獲得 min 和 max 的乘積。 ## C++ ``` // C++ program to find the to? // calculate the product of? // max element of first array // and min element of second array #include <bits/stdc++.h> using namespace std; // Function to calculate the product int minMaxProduct(int arr1[], int arr2[],? ??????????????????int n1, int n2) { ????// Initialize max of first array ????int max = arr1[0]; ????// initialize min of second array ????int min = arr2[0]; ????int i; ????for (i = 1; i < n1 && i < n2; ++i)? ????{ ????????// To find the maximum? ????????// element in first array ????????if (arr1[i] > max) ????????????max = arr1[i]; ????????// To find the minimum? ????????// element in second array ????????if (arr2[i] < min) ????????????min = arr2[i]; ????} ????// Process remaining elements ????while (i < n1) ????{ ????????if (arr1[i] > max) ????????max = arr1[i];? ????????i++; ????} ????while (i < n2) ????{ ????????if (arr2[i] < min) ????????min = arr2[i];? ????????i++; ????} ????return max * min; } // Driven code int main() { ????int arr1[] = { 10, 2, 3, 6, 4, 1 }; ????int arr2[] = { 5, 1, 4, 2, 6, 9 }; ????int n1 = sizeof(arr1) / sizeof(arr1[0]); ????int n2 = sizeof(arr1) / sizeof(arr1[0]); ????cout << minMaxProduct(arr1, arr2, n1, n2) ?????????<< endl; ????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>

                              哎呀哎呀视频在线观看