Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 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. ok=1;
  24. while(ok==1)
  25. {
  26. if(abs(mat[st][dr]-mat[indice][indice2-copie]))
  27. {
  28. ok=1;
  29. if(indice==st2 && indice2-copie==dr2)
  30. {
  31. roci++;
  32. ok=0;
  33. }
  34. else if(indice2-copie==1)
  35. {
  36. indice--;
  37. indice2 = n;
  38. if(indice==st2 && indice2==dr)
  39. {
  40. roci++;
  41. ok=0;
  42. }
  43. else
  44. copie=1;
  45. }
  46. copie++;
  47. }
  48. }
  49. }
  50. else if(st2>st)
  51. {
  52. indice = st;
  53. indice2 = dr;
  54. copie = 1;
  55. ok=1;
  56. while(ok==1)
  57. {
  58. if(abs(mat[st][dr]-mat[indice][indice2+copie])<=e)
  59. {
  60. ok=1;
  61. if(indice==st2 && indice2+copie == dr2)
  62. {
  63. roci++;
  64. ok=0;
  65. }
  66. if(indice2+copie==n)
  67. {
  68. indice++;
  69. indice2=1;
  70. if(st2==indice && indice2 == dr2)
  71. {
  72. roci++;
  73. ok=0;
  74. }
  75. else
  76. copie = 0;
  77. }
  78. copie++;
  79. }
  80. else
  81. ok=0;
  82.  
  83. }
  84. }
  85. else if(st==st2)
  86. {
  87. if(dr2>dr)
  88. {
  89. indice = st;
  90. indice2 = dr;
  91. ok=1;
  92. copie = 1;
  93. while(ok==1)
  94. {
  95. if(abs(mat[st][dr]-mat[indice][indice2+copie])<=e)
  96. {
  97. ok=1;
  98. if(indice==st2 && indice2+copie == dr2)
  99. {
  100. roci++;
  101. ok=0;
  102. }
  103. if(dr+indice2==n)
  104. {
  105. indice++;
  106. indice2 = 1;
  107. if(st2==indice && dr2==indice2)
  108. {
  109. roci++;
  110. ok=0;
  111. }
  112. else
  113. copie = 1;
  114. }
  115. copie++;
  116. }
  117. else
  118. ok=0;
  119.  
  120. }
  121. }
  122. else if(dr>dr2)
  123. {
  124. indice = st;
  125. indice2 = dr;
  126. copie = 1;
  127. ok=1;
  128. while(ok==1)
  129. {
  130. if(abs(mat[st][dr]==mat[indice][indice2-copie]))
  131. {
  132.  
  133. if(indice==st2 && indice2-copie == dr2)
  134. {
  135. roci++;
  136. ok=0;
  137. }
  138. if(indice2-copie==1)
  139. {
  140. indice--;
  141. indice2 = n;
  142. if(indice==st2 && indice2==dr2)
  143. {
  144. roci++;
  145. ok=0;
  146. }
  147. else
  148. copie=0;
  149. }
  150. copie++;
  151. }
  152. }
  153. }
  154. else if(dr==dr2)
  155. roci++;
  156. }
  157.  
  158. }
  159. fout << roci;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement