Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin ("marte.in");
  5. ofstream fout ("marte.out");
  6. int n,e,p,st,dr,mat[105][105],roci=0,st2,dr2,indice,indice2,ok,copie;
  7. int main()
  8. {
  9. fin >> n >> e >> p >> st >> dr;
  10. for(int i=1;i<=n;++i)
  11. {
  12. for(int j=1;j<=n;++j)
  13. fin >> mat[i][j];
  14. }
  15. for(int i=1;i<=p;++i)
  16. {
  17. fin >> st2 >> dr2;
  18. if(st>st2)
  19. {
  20. indice = st;
  21. indice2 = dr;
  22. copie = 1;
  23. while(ok==1)
  24. {
  25. if(abs(mat[st][dr]-mat[indice][indice2-copie]))
  26. {
  27. ok=1;
  28. if(indice==st2 && indice2-copie==dr2)
  29. {
  30. roci++;
  31. break;
  32. }
  33. else if(indice2-copie==1)
  34. {
  35. indice--;
  36. indice2 = n;
  37. copie = 0;
  38. }
  39. copie++;
  40. }
  41. }
  42. }
  43. else if(st2>st)
  44. {
  45. indice = st;
  46. indice2 = 1;
  47. while(ok==1)
  48. {
  49. if(abs(mat[st][dr]-mat[indice][dr+indice2])<=e)
  50. {
  51. ok=1;
  52. if(st==st2 && dr+indice2 == dr2)
  53. {
  54. roci++;
  55. break;
  56. }
  57. if(dr+indice2==n)
  58. {
  59. indice++;
  60. indice2=1;
  61. }
  62. indice2++;
  63. }
  64. else
  65. break;
  66.  
  67. }
  68. }
  69. else if(st==st2)
  70. {
  71. if(dr2>dr)
  72. {
  73. indice = st;
  74. indice2 = dr;
  75. ok=1;
  76. copie = 1;
  77. while(ok==1)
  78. {
  79. if(abs(mat[st][dr]-mat[indice][indice2+copie])<=e)
  80. {
  81. ok=1;
  82. if(indice==st2 && indice2+copie == dr2)
  83. {
  84. roci++;
  85. break;
  86. }
  87. if(dr+indice2==n)
  88. {
  89. indice++;
  90. indice2 = 1;
  91. if(st2==indice && dr2==indice2)
  92. {
  93. roci++;
  94. break;
  95. }
  96. else
  97. copie = 1;
  98. }
  99. copie++;
  100. }
  101. else
  102. break;
  103.  
  104. }
  105. }
  106. else if(dr>dr2)
  107. {
  108. indice = st;
  109. indice2 = dr;
  110. copie = 1;
  111. while(ok==1)
  112. {
  113. if(abs(mat[st][dr]==mat[indice][indice2-copie]))
  114. {
  115. if(indice==st2 && indice2-copie == dr)
  116. {
  117. roci++;
  118. break;
  119. }
  120. if(indice2-copie==1)
  121. {
  122. indice--;
  123. indice2 = n;
  124. copie = 0;
  125. }
  126. copie++;
  127. }
  128. }
  129. }
  130. else if(dr==dr2)
  131. roci++;
  132. }
  133.  
  134. }
  135. fout << roci;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement