Source code for submission s605

Go to diff to previous submission

ololo1.cpp

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <memory.h>
  6. #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
  7. #define FI(i,b) FOR(i,0,b)
  8. #define V(t) vector < t >
  9. #define pb push_back
  10. #define MEMS(a,b) memset((a),(b),sizeof(a))
  11. using namespace std;
  12.  
  13. int dx[]={1,1,-1,-1,2,2,-2,-2};
  14. int dy[]={2,-2,2,-2,1,-1,1,-1};
  15. int n,m;
  16. int was[110][110];
  17. int p[110*110][2];
  18. int d[110][110];
  19. inline bool iscor(int x, int y)
  20. {
  21. return ((x>=0) && (y>=0) && (x<=n-1) && (y<=m-1));
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27. int xs,ys,xt,yt;
  28. while (scanf("%d%d%d%d%d%d",&n,&m,&xs,&ys,&xt,&yt)!=EOF)
  29. {
  30. MEMS(was,0);
  31. //MEMS(p,0);
  32. //MEMS(d,0);
  33. int l=0,r=0;
  34. xs--; ys--; xt--; yt--;
  35. was[xs][ys]=1;
  36. d[xs][ys]=0;
  37. p[0][0]=xs;
  38. p[0][1]=ys;
  39. int res=-1;
  40. while (l<=r)
  41. {
  42. int x=p[l][0];
  43. int y=p[l][1];
  44. if ((x==xt) && (y==yt))
  45. {
  46. res=d[x][y];
  47. break;
  48. }
  49. FOR(k,0,8)
  50. {
  51. int nx=x+dx[k];
  52. int ny=y+dy[k];
  53. if ((iscor(nx,ny)) && (was[nx][ny]==0))
  54. {
  55. was[nx][ny]=1;
  56. d[nx][ny]=d[x][y]+1;
  57. r++;
  58. p[r][0]=nx;
  59. p[r][1]=ny;
  60. }
  61. }
  62. l++;
  63. }
  64. if (res>=0)
  65. printf("%d\n",res);
  66. else
  67. printf("impossible\n");
  68. }
  69. return 0;
  70. }

Diff to submission s592

ololo.cpp

--- c4.s592.cteam050.grasshop.cpp.0.ololo.cpp
+++ c4.s605.cteam050.grasshop.cpp.0.ololo1.cpp
@@ -32,4 +32,5 @@
     //MEMS(d,0);
     int l=0,r=0;
+    xs--; ys--; xt--; yt--;
     was[xs][ys]=1;
     d[xs][ys]=0;
@@ -50,5 +51,5 @@
         int nx=x+dx[k];
         int ny=y+dy[k];
-        if (iscor(nx,ny) && (was[nx][ny]==0))
+        if ((iscor(nx,ny)) && (was[nx][ny]==0))
         {
           was[nx][ny]=1;