SHARE
TWEET

Untitled

a guest Oct 21st, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin("bila.in");
  5. ofstream fout("bila.out");
  6. int n, m, b[21][21], i1, j1, maxim = -1;
  7. int a[21][21];
  8. int cnt;
  9. bool gasit = false;
  10. const int di[] = {-1, -1, -1, 0, 1, 1, 1, 0};
  11. const int dj[] = {-1, 0, 1, 1, 1, 0, -1, -1};
  12. void citire();
  13. void afisare();
  14. int interior(int i, int j);
  15. void back(int i, int j, int k);
  16. int margine(int i, int j);
  17. int main()
  18. {
  19.    citire();
  20.    b[i1][j1] = 1;
  21.    back(i1, j1, 2);
  22.    fout << cnt;
  23. }
  24. int interior(int i, int j)
  25. {
  26.     return i >= 1 && i <= n && j <= m && j >= 1;
  27. }
  28. void citire()
  29. {
  30.     fin >> n >> m;
  31.     for(int i = 1; i <= n; i++)
  32.         for(int j = 1; j <= m; j++)
  33.         fin >> a[i][j];
  34.     fin >> i1 >> j1;
  35. }
  36. void afisare()
  37. {
  38.     for(int i = 1; i <= n; i++)
  39.     {
  40.         for(int j = 1; j <= m; j++)
  41.         fout << b[i][j] << " ";
  42.         fout << endl;
  43.     }
  44.     fout << endl;
  45. }
  46. int margine(int i, int j)
  47. {
  48.     return i == 1 || i == n || j == 1 || j == m;
  49. }
  50. void back(int i, int j, int k)
  51. {
  52.         for(int d = 0; d < 8; d++)
  53.         {
  54.             int inou = i + di[d];
  55.             int jnou = j + dj[d];
  56.             if(interior(inou, jnou) && a[inou][jnou] < a[i][j])
  57.             {
  58.                 b[inou][jnou] = k;
  59.                if(margine(inou, jnou))
  60.                 {
  61.                     cnt++;
  62.                     afisare();
  63.                 }
  64.                 else
  65.                     back(inou, jnou, k + 1);
  66.                 b[inou][jnou] = 0;
  67.             }
  68.         }
  69.  
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top