<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-flip-required-make-binary-matrix-symmetric/](https://www.geeksforgeeks.org/minimum-flip-required-make-binary-matrix-symmetric/) 給定大小為 **N X N** 的二進制矩陣,由 1 和 0 組成。 任務是找到使矩陣沿[主對角線](https://en.wikipedia.org/wiki/Main_diagonal)對稱所需的最小翻轉。 **示例**: ``` Input : mat[][] = { { 0, 0, 1 }, { 1, 1, 1 }, { 1, 0, 0 } }; Output : 2 Value of mat[1][0] is not equal to mat[0][1]. Value of mat[2][1] is not equal to mat[1][2]. So, two flip are required. Input : mat[][] = { { 1, 1, 1, 1, 0 }, { 0, 1, 0, 1, 1 }, { 1, 0, 0, 0, 1 }, { 0, 1, 0, 1, 0 }, { 0, 1, 0, 0, 1 } }; Output : 3 ``` **方法 1(簡單)**: 這個想法是找到矩陣的轉置并找到使轉置和原始矩陣相等所需的最小翻轉次數。 要找到最小翻轉,請找到原始矩陣和轉置矩陣不相同的位置數,例如 x。 因此,我們的答案將是 x / 2。 以下是此方法的實現: ## C++ ```cpp // CPP Program to find minimum flip required to make // Binary Matrix symmetric along main diagonal #include <bits/stdc++.h> #define N 3 using namespace std; // Return the minimum flip required to make // Binary Matrix symmetric along main diagonal. int minimumflip(int mat[][N], int n) { ????int transpose[n][n]; ????// finding the transpose of the matrix ????for (int i = 0; i < n; i++) ????????for (int j = 0; j < n; j++) ????????????transpose[i][j] = mat[j][i]; ????// Finding the number of position where ????// element are not same. ????int flip = 0; ????for (int i = 0; i < n; i++) ????????for (int j = 0; j < n; j++) ????????????if (transpose[i][j] != mat[i][j]) ????????????????flip++; ????return flip / 2; } // Driver Program int main() { ????int n = 3; ????int mat[N][N] = { ????????{ 0, 0, 1 }, ????????{ 1, 1, 1 }, ????????{ 1, 0, 0 } ????}; ????cout << minimumflip(mat, n) << 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>

                              哎呀哎呀视频在线观看