Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. ifstream in("cartite.in");
  7. ofstream out("cartite.out");
  8.  
  9. typedef pair < bool , pair < int, int > > Pair;
  10. const int NMAX=210, dX[]= {-1, 0, 1, 0, -2, -1, 0, 1, 2, 1, 0, -1}, dY[]= {0, 1, 0, -1, 0, 1, 2, 1, 0, -1, -2, -1};
  11. int Question, n, m, xc, yc, K, G, Mat[NMAX][NMAX], a[NMAX][NMAX], rX, rY;
  12. deque < pair < int, int > > Q;
  13. map < pair < int, int >, vector < pair < bool, pair < int, int > > > > MAP;
  14. vector < pair < int, int > > R;
  15.  
  16. void Mark(int x, int y, int c)
  17. {
  18. int z=-1, NewX, NewY;
  19. Mat[x][y] = -1;
  20. if(c == 1)
  21. z = 3;
  22. if(c == 2)
  23. z = 11;
  24. for(int i = 0; i <=z; i++)
  25. {
  26. NewX = x + dX[i];
  27. NewY = y + dY[i];
  28. if(NewX < 1 || NewX > n || NewY < 1 || NewY > m)
  29. continue;
  30. Mat[NewX][NewY] = -1;
  31. }
  32. }
  33.  
  34. bool INSIDE(int x, int y)
  35. {
  36. if(x < 1 || x > n || y < 1 || y > m)
  37. return 0;
  38. return 1;
  39. }
  40.  
  41. void Lee(int x, int y)
  42. {
  43. if(Mat[x][y] == 1)
  44. {
  45. rX = x;
  46. rY = y;
  47. return;
  48. }
  49. a[x][y]=1;
  50. int NewX, NewY;
  51. Q.push_back(make_pair(x, y));
  52. while(!Q.empty())
  53. {
  54. x = Q.front().first;
  55. y = Q.front().second;
  56. Q.pop_front();
  57. for(int z = 0; z < 4; z++)
  58. {
  59. NewX = x + dX[z];
  60. NewY = y + dY[z];
  61. if(INSIDE(NewX, NewY) && !a[NewX][NewY] && Mat[NewX][NewY]!=-1)
  62. {
  63. Q.push_back(make_pair(NewX, NewY));
  64. a[NewX][NewY] = a[x][y] + 1;
  65. if(Mat[NewX][NewY] == 1)
  66. {
  67. rX = NewX;
  68. rY = NewY;
  69. return;
  70. }
  71. }
  72. }
  73. }
  74. }
  75.  
  76. void DFS(int x, int y)
  77. {
  78. for(Pair it : MAP[{x, y}])
  79. if(it.first)
  80. {
  81. it.first = 0;
  82. for(Pair i : MAP[{it.second.first, it.second.second}])
  83. if(i.second.first == x && i.second.second == y)
  84. {
  85. i.first = 0;
  86. break;
  87. }
  88. DFS(it.second.first, it.second.second);
  89. }
  90. R.push_back(make_pair(x, y));
  91.  
  92. }
  93.  
  94. void Read_Solve()
  95. {
  96. ios::sync_with_stdio(false);
  97. in.tie(NULL);
  98. int x1, y1, x2, y2;
  99. in >> Question >> n >> m >> xc >> yc >> K;
  100. for(int i = 1; i <= K; i++)
  101. {
  102. in >> x1 >> y1 >> x2;
  103. Mark(x1, y1, x2);
  104. }
  105. in >> G;
  106. for(int i = 1; i <= G; i++)
  107. {
  108. in >> x1 >> y1 >> x2 >> y2;
  109. MAP[ {x1, y1}].push_back({1, {x2, y2}});
  110. MAP[ {x2, y2}].push_back({1, {x1, y1}});
  111. if(!Mat[x1][y1])
  112. Mat[x1][y1] = 1;
  113. if(!Mat[x2][y2])
  114. Mat[x2][y2] = 1;
  115. }
  116. if(Question == 1)
  117. {
  118. Lee(xc, yc);
  119. out << rX << ' ' << rY << ' ' << a[rX][rY]-1;
  120. return;
  121. }
  122. DFS(x1, y1);
  123. for(pair < int, int > it : R)
  124. out << it.first << ' ' << it.second << '\n';
  125. }
  126.  
  127. int main()
  128. {
  129. Read_Solve();
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement