Advertisement
hegemon88676

alee lee

Feb 23rd, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int a[100][100], dl[]={-1, 1, 0 ,0}, dc[]={0, 0, 1, -1}, n, x1, y1, x2, y2, p, u;
  6.  
  7. struct
  8. {
  9. int lin, col;
  10.  
  11. }c[100];
  12.  
  13. bool ok(int x, int y)
  14. {
  15. if(a[x][y]!=0 || x>n || y>n || x<1 || y<1)
  16. return false;
  17. return true;
  18. }
  19.  
  20. void citire()
  21. {
  22. ifstream f("alee.in");
  23. f>>n;
  24. f>>x1>>y1>>x2>>y2;
  25. int i, j;
  26. while(f>>i>>j)
  27. a[i][j]=-1;
  28. }
  29.  
  30. void lee()
  31. {
  32. int i, j, i_urm, j_urm, dir;
  33. p=u=1;
  34. c[1].lin=x1;
  35. c[1].col=y1;
  36. a[x1][y1]=1;
  37.  
  38. while(p<=u)
  39. {
  40. i=c[p].lin;
  41. j=c[p].col;
  42. for(dir=0;dir<4;dir++)
  43. {
  44. i_urm=i+dl[dir];
  45. j_urm=j+dc[dir];
  46. if(ok(i_urm, j_urm)==true)
  47. {
  48. u++;
  49. c[u].lin=i_urm;
  50. c[u].col=j_urm;
  51. a[i_urm][j_urm]=a[i][j]+1;
  52. }
  53. }
  54. p++;
  55. }
  56. }
  57.  
  58. int main()
  59. {
  60. citire();
  61. lee();
  62. cout<<a[x2][y2];
  63. }
  64. /*
  65. 8
  66. 2 1 8 8
  67. 2 3
  68. 3 5
  69. 5 7
  70. 8 7
  71. 6 3
  72. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement