SHARE
TWEET

Untitled

a guest Dec 16th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<fstream>
  2.  
  3. #include<iostream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream f("lab.in");
  8.  
  9. ofstream g("lab.out");
  10.  
  11. int n,m,lab[12][12],s[12][12],is,js,ib,jb,sol;
  12.  
  13. int dx[]= {0,-1,0,1,0};
  14.  
  15. int dy[]= {0, 0,1,0,-1};
  16.  
  17. void citire()
  18.  
  19. {
  20.  
  21.     f>>n>>m;
  22.  
  23.     for(int i=1; i<=n; i++)
  24.  
  25.         for(int j=1; j<=m; j++)
  26.  
  27.             f>>lab[i][j];
  28.  
  29.     f>>is>>js>>ib>>jb;
  30.  
  31. }
  32.  
  33. void afis()
  34.  
  35. {
  36.  
  37.     int i, j;
  38.  
  39.     for(i=1;i<=n;i++)
  40.  
  41.     {
  42.  
  43.         for(j=1;j<=m;j++)
  44.  
  45.             cout<<s[i][j]<<" ";
  46.  
  47.         cout<<endl;
  48.  
  49.     }
  50.  
  51.     cout<<endl;
  52.  
  53. }
  54.  
  55. void traseu(int i, int j, int pas)
  56.  
  57. {
  58.  
  59.     int i1, j1, k;
  60.  
  61.     for(int k=1; k<=4; k++)
  62.  
  63.     {
  64.  
  65.         i1=i+dx[k];
  66.  
  67.         j1=j+dy[k];
  68.  
  69.         if(i1>=1&&i1<=n&&j1>=1&&j1<=m)
  70.  
  71.             if(lab[i1][j1]==0&&s[i1][j1]==0)
  72.  
  73.             {
  74.  
  75.                 s[i1][j1]=pas;
  76.  
  77.                 if(i1==ib&&j1==jb) afis();
  78.  
  79.                 traseu(i1, j1, pas+1);
  80.  
  81.                 s[i1][j1]=0;
  82.  
  83.             }
  84.  
  85.     }
  86.  
  87. }
  88.  
  89. int main()
  90.  
  91. {
  92.  
  93.     citire();
  94.  
  95.     s[is][js]=1;
  96.  
  97.     traseu(is,js,2);
  98.  
  99.     return 0;
  100.  
  101. }
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