<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/find-permuted-rows-given-row-matrix/](https://www.geeksforgeeks.org/find-permuted-rows-given-row-matrix/) 給我們一個由正整數和行號組成的 m * n 矩陣。 任務是在給定矩陣中找到所有行,這些行是給定行元素的排列。 還假定每一行中的值都是不同的。 例子: ``` Input : mat[][] = {{3, 1, 4, 2}, {1, 6, 9, 3}, {1, 2, 3, 4}, {4, 3, 2, 1}} row = 3 Output: 0, 2 Rows at indexes 0 and 2 are permutations of row at index 3. ``` **簡單解決方案**是對所有行逐一排序并檢查所有行。 如果任何行與給定行完全相等,則意味著當前行是給定行的排列。 此方法的時間復雜度將為 O(m * n log n)。 **有效方法**是使用哈希。 只需為給定的行創建[哈希集](https://www.geeksforgeeks.org/unorderd_set-stl-uses/)。 創建哈希集后,遍歷其余行,并針對每一行檢查其所有元素是否存在于哈希集中。 ## CPP ``` // C++ program to find all permutations of a given row #include<bits/stdc++.h> #define MAX 100 using namespace std; // Function to find all permuted rows of a given row r void permutatedRows(int mat[][MAX], int m, int n, int r) { ????// Creating an empty set ????unordered_set<int> s; ????// Count frequencies of elements in given row r ????for (int j=0; j<n; j++) ????????s.insert(mat[r][j]); ????// Traverse through all remaining rows ????for (int i=0; i<m; i++) ????{ ????????// we do not need to check for given row r ????????if (i==r) ????????????continue; ????????// initialize hash i.e; count frequencies ????????// of elements in row i ????????int j; ????????for (j=0; j<n; j++) ????????????if (s.find(mat[i][j]) == s.end()) ????????????????break; ????????if (j != n) ???????????continue; ????????cout << i << ", "; ????} } // Driver program to run the case int main() { ????int m = 4, n = 4,r = 3; ????int mat[][MAX] = {{3, 1, 4, 2}, ??????????????????????{1, 6, 9, 3}, ??????????????????????{1, 2, 3, 4}, ??????????????????????{4, 3, 2, 1}}; ????permutatedRows(mat, m, n, r); ????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>

                              哎呀哎呀视频在线观看