Advertisement
Guest User

labirint

a guest
Nov 12th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int n,m,p,a[100][100],i,j,d[10],di[]= {-1,-1,0,1,1,1,0,-1}, dj[]= {0,1,1,1,0,-1,-1,-1},li,ci,lf,cf;
  5. struct elemente
  6. {
  7. int l,c;
  8. } st[100];
  9. int valid(int p)
  10. {
  11. int ok=1;
  12. for(i=1; i<p; i++)
  13. if(st[i].l==st[p].l && st[i].c==st[p].c)
  14. ok=0;
  15. if(a[st[p].l][st[p].c]==1)
  16. ok=0;
  17. if(st[p].l<1 || st[p].l>m || st[p].c<1 || st[p].c>n)
  18. ok=0;
  19. return ok;
  20. }
  21. void tipar(int p)
  22. {
  23. for(i=1; i<=p; i++)
  24. {
  25. cout<<st[i].l<<" "<<st[i].c;
  26. cout<<endl;
  27. }
  28. cout<<endl;
  29. }
  30. int main()
  31. {
  32. ifstream f("date.in");
  33. f>>m>>n>>li>>ci>>lf>>cf;
  34. for(i=1; i<=m; i++)
  35. for(j=1; j<=n; j++)
  36. f>>a[i][j];
  37. p=1;
  38. st[p].l=li;
  39. st[p].c=ci;
  40. p=2;
  41. d[p]=-1;
  42. while(p>1)
  43. if(d[p]<7)
  44. {
  45. d[p]++;
  46. st[p].l=st[p-1].l+di[d[p]];
  47. st[p].c=st[p-1].c+dj[d[p]];
  48. if(valid(p)==1)
  49. if(st[p].l==lf && st[p].c==cf)
  50. tipar(p);
  51. else
  52. {
  53. p++;
  54. d[p]=-1;
  55. }
  56. } else p--;
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement