<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/count-sorted-rows-matrix/](https://www.geeksforgeeks.org/count-sorted-rows-matrix/) 給定一個 m * n 大小的矩陣,任務是對矩陣中按嚴格遞增順序或嚴格遞減順序排序的所有行進行計數嗎? **示例**: ``` Input : m = 4, n = 5 mat[m][n] = 1 2 3 4 5 4 3 1 2 6 8 7 6 5 4 5 7 8 9 10 Output: 3 ``` 這個想法很簡單,涉及矩陣的兩個遍歷。 1)從矩陣左側遍歷以嚴格按**順序遞增的所有行** 2)從矩陣右側遍歷以對[[ **嚴格降序** 以下是上述想法的實現。 ## C++ ```cpp // C++ program to find number of sorted rows #include <bits/stdc++.h> #define MAX 100 using namespace std; // Function to count all sorted rows in a matrix int sortedCount(int mat[][MAX], int r, int c) { ????int result = 0; // Initialize result ????// Start from left side of matrix to ????// count increasing order rows ????for (int i=0; i<r; i++) ????{ ????????// Check if there is any pair ofs element ????????// that are? not in increasing order. ????????int j; ????????for (j=0; j<c-1; j++) ????????????if (mat[i][j+1] <= mat[i][j]) ????????????????break; ????????// If the loop didn't break (All elements ????????// of current row were in increasing order) ????????if (j == c-1) ????????????result++; ????} ????// Start from right side of matrix to ????// count increasing order rows ( reference ????// to left these are in decreasing order ) ????for (int i=0; i<r; i++) ????{ ????????// Check if there is any pair ofs element ????????// that are? not in decreasing order. ????????int j; ????????for (j=c-1; j>0; j--) ????????????if (mat[i][j-1] <= mat[i][j]) ????????????????break; ????????// Note c > 1 condition is required to make ????????// sure that a single column row is not counted ????????// twice (Note that a single column row is sorted ????????// both in increasing and decreasing order)? ????????if (c > 1 && j == 0) ????????????result++; ????} ????return result; } // Driver program to run the case int main() { ????int m = 4, n = 5; ????int mat[][MAX] = {{1, 2, 3, 4, 5}, ??????????????????????{4, 3, 1, 2, 6}, ??????????????????????{8, 7, 6, 5, 4}, ??????????????????????{5, 7, 8, 9, 10}}; ????cout << sortedCount(mat, m, 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>

                              哎呀哎呀视频在线观看