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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 布爾矩陣問題 > 原文: [https://www.geeksforgeeks.org/a-boolean-matrix-question/](https://www.geeksforgeeks.org/a-boolean-matrix-question/) 給定大小為 MXN 的布爾矩陣 mat [M] [N],請對其進行修改,以使如果矩陣單元 mat [i] [j]為 1(或 true),則使第 i 行和第 j 列的所有單元格均為 1。 ``` Example 1 The matrix 1 0 0 0 should be changed to following 1 1 1 0 Example 2 The matrix 0 0 0 0 0 1 should be changed to following 0 0 1 1 1 1 Example 3 The matrix 1 0 0 1 0 0 1 0 0 0 0 0 should be changed to following 1 1 1 1 1 1 1 1 1 0 1 1 ``` **方法 1(使用兩個臨時數組)** 1)創建兩個臨時數組 row [M]和 col [N]。 將 row []和 col []的所有值初始化為 0。 2)遍歷輸入矩陣 mat [M] [N]。 如果看到輸入 mat [i] [j]為 true,則將 row [i]和 col [j]標記為 true。 3)再次遍歷輸入矩陣 mat [M] [N]。 對于每個入口 mat [i] [j],檢查 row [i]和 col [j]的值。 如果兩個值(row [i]或 col [j])中的任何一個為 true,則將 mat [i] [j]標記為 true。 感謝 Dixit Sethi 提出了這種方法。 ## C++ ```cpp // C++ Code For A Boolean Matrix Question #include <bits/stdc++.h> using namespace std; #define R 3 #define C 4 void modifyMatrix(bool mat[R][C]) { ????bool row[R]; ????bool col[C]; ????int i, j; ????/* Initialize all values of row[] as 0 */ ????for (i = 0; i < R; i++) ????{ ????row[i] = 0; ????} ????/* Initialize all values of col[] as 0 */ ????for (i = 0; i < C; i++) ????{ ????col[i] = 0; ????} ????// Store the rows and columns to be marked as ????// 1 in row[] and col[] arrays respectively ????for (i = 0; i < R; i++) ????{ ????????for (j = 0; j < C; j++) ????????{ ????????????if (mat[i][j] == 1) ????????????{ ????????????????row[i] = 1; ????????????????col[j] = 1; ????????????} ????????} ????} ????// Modify the input matrix mat[] using the? ????// above constructed row[] and col[] arrays ????for (i = 0; i < R; i++) ????{ ????????for (j = 0; j < C; j++) ????????{ ????????????if ( row[i] == 1 || col[j] == 1 ) ????????????{ ????????????????mat[i][j] = 1; ????????????} ????????} ????} } /* A utility function to print a 2D matrix */ void printMatrix(bool mat[R][C]) { ????int i, j; ????for (i = 0; i < R; i++) ????{ ????????for (j = 0; j < C; j++) ????????{ ????????????cout << mat[i][j]; ????????} ????????cout << endl; ????} } // Driver Code int main() { ????bool mat[R][C] = { {1, 0, 0, 1}, ???????????????????????{0, 0, 1, 0}, ???????????????????????{0, 0, 0, 0}}; ????cout << "Input Matrix \n"; ????printMatrix(mat); ????modifyMatrix(mat); ????printf("Matrix after modification \n"); ????printMatrix(mat); ????return 0; } // This code is contributed? // by Akanksha Rai(Abby_akku) ```
                  <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>

                              哎呀哎呀视频在线观看