Dang_Quan_10_Tin

CAU4 HSGHN L9 2015-2016

Dec 24th, 2021
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #define task "CAU4"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. constexpr int N = 1e2 + 5;
  9. int m, n, t;
  10. int a[N][N];
  11. bool keep[N][N]; // Có giữ lại cây này hay không
  12.  
  13. void Read()
  14. {
  15.     cin >> m >> n >> t;
  16.  
  17.     for (int i = 1; i <= m; ++i)
  18.         for (int j = 1; j <= n; ++j)
  19.             cin >> a[i][j];
  20. }
  21.  
  22. void Solve()
  23. {
  24.     for (int i = 1; i <= m; ++i)
  25.         for (int j = 1; j <= n; ++j)
  26.             if (a[i][j] != 0) // Có chậu cây ở đây mới xét
  27.             {
  28.                 int h = j;
  29.                 while (h <= n && a[i][h] == a[i][j])
  30.                     ++h;
  31.  
  32.                 if (h - j >= t) // Hàng cây đẹp
  33.                     while (j < h)
  34.                     {
  35.                         keep[i][j] = 1;
  36.                         ++j;
  37.                     }
  38.  
  39.                 j = h - 1; // Một phép nhảy
  40.             }
  41.  
  42.     // Làm tương tự với các cột
  43.  
  44.     for (int i = 1; i <= n; ++i)
  45.         for (int j = 1; j <= m; ++j)
  46.             if (a[j][i] != 0) // Có chậu cây ở đây mới xét
  47.             {
  48.                 int h = j;
  49.                 while (h <= m && a[h][i] == a[j][i])
  50.                     ++h;
  51.  
  52.                 if (h - j >= t) // Hàng cây đẹp
  53.                     while (j < h)
  54.                     {
  55.                         keep[j][i] = 1;
  56.                         ++j;
  57.                     }
  58.  
  59.                 j = h - 1; // Một phép nhảy
  60.             }
  61.  
  62.     int ans(0);
  63.  
  64.     for (int i = 1; i <= m; ++i)
  65.         for (int j = 1; j <= n; ++j)
  66.             if (a[i][j] != 0 && !keep[i][j]) // Có chậu cây ở ô này và nó không thuộc hàng cây tốt nào cả
  67.                 ++ans;
  68.  
  69.     cout << ans;
  70. }
  71.  
  72. int32_t main()
  73. {
  74.     ios::sync_with_stdio(0);
  75.     cin.tie(0);
  76.     cout.tie(0);
  77.     if (fopen(task ".INP", "r"))
  78.     {
  79.         freopen(task ".INP", "r", stdin);
  80.         freopen(task ".OUT", "w", stdout);
  81.     }
  82.  
  83.     Read();
  84.     Solve();
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment