Advertisement
Tooster

lasery i przepinanie wskaźników

Dec 12th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <map>
  3.  
  4. using namespace std;
  5.  
  6. int max_v = 1;
  7. int v = 1;
  8.  
  9. struct booster{
  10. int x;
  11. int y;
  12. char c;
  13. booster *l;
  14. booster *r;
  15. booster *u;
  16. booster *d;
  17. int OFF;
  18. booster(int x = 0, int y = 0, char c = 0){
  19. this->x = x;
  20. this->y = y;
  21. this->c = c;
  22. this->l = NULL;
  23. this->r = NULL;
  24. this->u = NULL;
  25. this->d = NULL;
  26. OFF = -1;
  27. }
  28. };
  29.  
  30. bool comp_x(const booster &a,const booster &b){
  31. return (a.x < b.x || (a.x == b.x && a.y < b.y));
  32. }
  33.  
  34. bool comp_y(const booster &a,const booster &b){
  35. return (a.y < b.y || (a.y == b.y && a.x < b.x));
  36. }
  37.  
  38. int main(){
  39. int n;
  40. scanf("%d", &n);
  41. vector<booster> tab;
  42. vector<bool> vis(n);
  43.  
  44. // # CZYTANIE #
  45. for(int i=0; i<n; i++){
  46. int a, b;
  47. char c;
  48. scanf("%d %d %c", &a, &b, &c);
  49. tab[i] = booster(a, b, c);
  50. }
  51.  
  52.  
  53.  
  54. int s = tab.size();
  55.  
  56.  
  57.  
  58.  
  59. sort(tab.begin(), tab.end(), comp_x); // ustawia UP/DOWN po przekątnej od LU do RD
  60.  
  61.  
  62. if(tab[0].x == tab[1].x && tab[0].y < tab[1].y)
  63. tab[0].d = &tab[1];
  64. if(tab[s-1].x == tab[s-2].x && tab[s-1].y > tab[s-2].y)
  65. tab[s-1].u = &tab[s-2];
  66.  
  67. for(int i = 1 ; i<s-1; i++){
  68. if(tab[i-1].x == tab[i].x) tab[i].u = &tab[i-1];
  69. if(tab[i+1].x == tab[i].x) tab[i].d = &tab[i+1];
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. sort(tab.begin(), tab.end(), comp_y); // ustawia LEFT/RIGHT tak samo
  80.  
  81. if(tab[0].y == tab[1].y && tab[0].x < tab[1].x)
  82. tab[0].r = &tab[1];
  83. if(tab[s-1].y == tab[s-2].y && tab[s-1].x > tab[s-2].x)
  84. tab[s-1].l = &tab[s-2];
  85.  
  86. for(int i = 1 ; i<tab.size()-1; i++){
  87. if(tab[i-1].y == tab[i].y) tab[i].l = &tab[i-1];
  88. if(tab[i+1].y == tab[i].y) tab[i].r = &tab[i+1];
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. for(int i=0; i<s; i++){
  99. v = 1;
  100. booster *next= &tab[i];
  101. next->OFF = i; //oznacza włączony
  102. while(next != NULL){
  103.  
  104. next->OFF = i;
  105.  
  106.  
  107. if (next->c == '^'){
  108. booster *tmp = next->u;
  109. while(tmp->OFF == i)
  110. tmp = tmp->u;
  111. next = tmp;
  112. }
  113.  
  114.  
  115.  
  116. else if(next->c == '<' ){
  117. booster *tmp = next->l;
  118. while(tmp->OFF == i)
  119. tmp = tmp->l;
  120. next = tmp;
  121. }
  122.  
  123.  
  124.  
  125. else if(next->c == 'v'){
  126. booster *tmp = next->d;
  127. while(tmp->OFF == i)
  128. tmp = tmp->d;
  129. next = tmp;
  130. }
  131.  
  132.  
  133.  
  134. else if(next->c == '>'){
  135. booster *tmp = next->r;
  136. while(tmp->OFF == i)
  137. tmp = tmp->r;
  138. next = tmp;
  139. }
  140.  
  141. v++;
  142. }
  143. if(v > max_v) max_v = v;
  144. }
  145.  
  146.  
  147.  
  148.  
  149. printf("%d", max_v);
  150. return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement