Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <fstream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ifstream f("date.in");
  9. ofstream g("date.out");
  10. int N,K,i,j,dl[]={-1,0,1,0},dc[]={0,1,0,-1},lc,cc,nr_pasi;
  11. f>>N>>K;
  12. int etaj[N+1][N+1],pasi[N+1][N+1];
  13. for(i=1;i<=N;i++)
  14. {
  15. for(j=1;j<=N;j++)
  16. {
  17. f>>etaj[i][j];
  18. if(etaj[i][j]!=0)
  19. pasi[i][j]=0;
  20. if(etaj[i][j]==0)
  21. pasi[i][j]=1;
  22. }
  23.  
  24. }
  25. for(i=0;i<=N+1;i++)
  26. {
  27. pasi[0][i]=-1;
  28. pasi[N+1][i]=-1;
  29. pasi[i][0]=-1;
  30. pasi[i][N+1]=-1;
  31. }
  32.  
  33.  
  34. struct coada{int l,c;};;
  35. struct nod{ coada inf;
  36. nod *urm;};
  37. nod *p,*u,*q;
  38. p=u=NULL;
  39. p=new nod;
  40. p->inf.l=1;
  41. p->inf.c=1;
  42. p->urm=NULL;
  43. u=p;
  44. pasi[1][1]=1;
  45. while(p<=u&&pasi[N][N]==0)
  46. {
  47. for(i=0;i<=3;i++)
  48. {
  49. lc=p->inf.l+dl[i];
  50. cc=p->inf.c+dc[i];
  51. if(pasi[lc][cc]==0)
  52. {
  53. q=new nod;
  54. q->inf.l=lc;
  55. q->inf.c=cc;
  56. q->urm=NULL;
  57. u->urm=q;
  58. u=q;
  59. pasi[lc][cc]=pasi[p->inf.l][p->inf.c]+1;
  60.  
  61. }
  62.  
  63. }
  64. p=p->urm;
  65. }
  66. nr_pasi=pasi[N][N];
  67. g<<nr_pasi;
  68.  
  69.  
  70.  
  71. return 0;
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement