Advertisement
Dang_Quan_10_Tin

CITY TS10 PTNK 2012-2013

Jan 15th, 2022
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #define task "CITY"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. using ll = long long;
  10. using ld = long double;
  11.  
  12. constexpr int N = 5e2 + 5;
  13. int m, n, k, l;
  14. int a[N][N], b[N][N], s[N * N];
  15.  
  16. void Read()
  17. {
  18.     cin >> m >> n >> k;
  19.  
  20.     for (int i = 1; i <= m; ++i)
  21.         for (int j = 1; j <= n; ++j)
  22.             cin >> a[i][j];
  23. }
  24.  
  25. void Solve()
  26. {
  27.     for (int i = 1; i <= m; ++i)
  28.         for (int j = 1; j <= n; ++j)
  29.         {
  30.             // Tính lượng lương thực sản xuất ra từ các ô kề
  31.             for (int t = -1; t <= 1; ++t)
  32.                 for (int h = -1; h <= 1; ++h)
  33.                     if (t != 0 || h != 0)
  34.                         b[i][j] += a[i + t][j + h];
  35.  
  36.             s[++l] = b[i][j]; // Duỗi ra mảng hai chiều
  37.         }
  38.  
  39.     sort(s + 1, s + l + 1);
  40.  
  41.     for (int i = 1; i <= k; ++i)
  42.     {
  43.         int c;
  44.         cin >> c;
  45.  
  46.         int j = lower_bound(s + 1, s + l + 1, c) - s;
  47.  
  48.         if (j <= l && s[j] == c)
  49.             cout << 1 << " ";
  50.         else
  51.             cout << 0 << " ";
  52.     }
  53. }
  54.  
  55. int32_t main()
  56. {
  57.     ios::sync_with_stdio(0);
  58.     cin.tie(0);
  59.     cout.tie(0);
  60.     if (fopen(task ".INP", "r"))
  61.     {
  62.         freopen(task ".INP", "r", stdin);
  63.         freopen(task ".OUT", "w", stdout);
  64.     }
  65.  
  66.     Read();
  67.     Solve();
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement