tonfain

whycowcrossroad3_tonfaiv1

Dec 21st, 2022
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct loc{
  5. int xc;
  6. int yc;
  7. };
  8.  
  9. struct rd{
  10. int r1;
  11. int c1;
  12. int r2;
  13. int c2;
  14. };
  15.  
  16.  
  17. inline bool operator<(const rd& rr1, const rd& rr2) {
  18. return tie(rr1.r1, rr1.c1, rr1.r2, rr1.c2)
  19. < tie(rr2.r1, rr2.c1, rr2.r2, rr2.c2);
  20. }
  21.  
  22. vector<vector<int>> grid;
  23. vector<vector<bool>> visited;
  24. set<rd> road;
  25. //vector<loc> road[100][100];
  26. vector<loc> cowLoc;
  27. bool reached = false;
  28. int N, K, R;
  29. //vector<vector<vector<pair<int, int>>>> road(100, vector<vector<pair<int, int>>>(100));
  30.  
  31. //bool isRoad(int a, int b, int a1, int b1){
  32. //if()
  33. //}
  34.  
  35. //map<loc, loc> road;
  36.  
  37. bool isRoad(rd r){
  38. if(road.find(r) != road.end()){
  39. return true;
  40. }
  41. return false;
  42. }
  43.  
  44. void dfs(loc u, loc en){
  45. //cout << "N: " << N << endl;
  46. //if(visited[0][2]){
  47. //cout << "visited[0][2]" << endl;
  48. //}
  49. if(visited[u.xc][u.yc]){
  50. //cout << "visited: " << u.xc << " " << u.yc << endl;
  51. return;
  52. }
  53. visited[u.xc][u.yc] = true;
  54. if(u.xc == en.xc && u.yc == en.yc){
  55. reached = true;
  56. }
  57. //loc v;
  58. if(u.xc > 0){
  59. //v.yc = u.yc;
  60. //v.xc = u.xc - 1;
  61. if(!isRoad(rd{u.xc, u.yc, u.xc - 1, u.yc})){
  62. //cout << "going left: curr coor: " << u.xc << " " << u.yc << ", next grid: " << u.xc - 1 << " " << u.yc << endl;
  63. dfs(loc{u.xc - 1, u.yc}, en);
  64. }else{
  65. //cout << "is Road" << endl;
  66. }
  67. }
  68. //cout << "u."
  69. if(u.xc < N-1){
  70. //v.xc = u.xc + 1;
  71. //v.yc = u.yc;
  72. if(!isRoad(rd{u.xc, u.yc, u.xc + 1, u.yc})){
  73. //cout << "going right: curr coor: " << u.xc << " " << u.yc << ", next grid: " << u.xc + 1 << " " << u.yc << endl;
  74. dfs(loc{u.xc + 1, u.yc}, en);
  75. }else{
  76. //cout << "is Road" << endl;
  77. }
  78. }else{
  79. //cout << "can't go right, u.xc: " << u.xc << ", N-1: " << N-1 << endl;
  80. }
  81. if(u.yc < N-1){
  82. //v.yc = u.yc+1;
  83. //v.xc = u.xc;
  84. if(!isRoad(rd{u.xc, u.yc, u.xc, u.yc+1})){
  85. //cout << "going up: curr coor: " << u.xc << " " << u.yc << ", next grid: " << u.xc << " " << u.yc+1 << endl;
  86. dfs(loc{u.xc, u.yc+1}, en);
  87. }else{
  88. //cout << "is Road" << endl;
  89. }
  90. }else{
  91. //cout << "can't go up, u.yc: " << u.yc << ", N-1: " << N-1 << endl;
  92. }
  93. if(u.yc > 0){
  94. //v.yc = u.yc-1;
  95. //v.xc = u.xc;
  96. if(!isRoad(rd{u.xc, u.yc, u.xc, u.yc-1})){
  97. //cout << "going down: curr coor: " << u.xc << " " << u.yc << ", next grid: " << u.xc << " " << u.yc-1 << endl;
  98. dfs(loc{u.xc, u.yc-1}, en);
  99. }else{
  100. //cout << "is Road" << endl;
  101. }
  102. }else{
  103. //cout << "can't "
  104. }
  105. }
  106.  
  107. int main(){
  108. ifstream fin("countcross.in");
  109. ofstream fout("countcross.out");
  110.  
  111. //int N, K, R;
  112. fin >> N >> K >> R;
  113. //cout << "N: " << N << endl;
  114. grid.resize(N, vector<int>(N));
  115. cowLoc.resize(K);
  116. visited.resize(100, vector<bool>(100));
  117. //visited.resize(N, 0);
  118.  
  119. for(int i = 0; i<R; i++){
  120. int x, y, x1, y1; fin >> x >> y >> x1 >> y1; x--; y--; x1--; y1--;
  121. //loc c1, c;
  122. //c1.xc = x1;
  123. //c1.yc = y1;
  124. //c.xc = x;
  125. //c.yc = y;
  126. //road.insert({x1, y1})
  127. road.insert(rd{x1, y1, x, y});
  128. road.insert(rd{x, y, x1, y1});
  129. //road[x][y].push_back(c1);
  130. //road[x1][y1].push_back(c);
  131. }
  132.  
  133. for(int i = 0; i<K; i++){
  134. int a, b; fin >> a >> b; a--; b--;
  135. cowLoc[i].xc = a;
  136. cowLoc[i].yc = b;
  137. }
  138.  
  139. for(int c = 0; c<N; c++){
  140. for(int d = 0; d<N; d++){
  141. visited[c][d] = false;
  142. }
  143. }
  144.  
  145. int ans = 0;
  146. for(int i = 0; i<K; i++){
  147. for(int j = 0; j<K; j++){
  148.  
  149. if(i == j) continue;
  150.  
  151. for(int c = 0; c<N; c++){
  152. for(int d = 0; d<N; d++){
  153. visited[c][d] = 0;
  154. }
  155. }
  156.  
  157. //visited.resize(N, 0);
  158.  
  159. loc start;
  160. start.xc = cowLoc[i].xc;
  161. start.yc = cowLoc[i].yc;
  162.  
  163. //cout << "start: " << start.xc << " " << start.yc << endl;
  164. loc dest;
  165. dest.xc = cowLoc[j].xc;
  166. dest.yc = cowLoc[j].yc;
  167. //cout << "destination: " << dest.xc << " " << dest.yc << endl;
  168.  
  169. reached = false;
  170. dfs(start, dest);
  171. //cout << "worked" << endl;
  172. if(!reached){
  173. ans++;
  174. }
  175.  
  176. }
  177. }
  178. fout << ans/2 << endl;
  179. }
  180.  
Advertisement
Add Comment
Please, Sign In to add comment