Advertisement
a53

Pelican

a53
Mar 23rd, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. static const int MAXP = 10000, MAXK = 100000, MAXCHAR = 128;
  5. static const int N = 0, E = 1, S = 2, V = 3;
  6.  
  7. struct Rata {
  8. int l, c, o;
  9. } virtuale[4], rate[MAXP];
  10.  
  11. struct Query {
  12. char com;
  13. int nr;
  14. } queries[MAXK];
  15.  
  16. // pt modulo negativ din c/c++
  17. int rest(const int a, const int b) {
  18. int retval = a % b;
  19. return retval >= 0 ? retval : retval + b;
  20. }
  21.  
  22. void adv(int& x, int& y, const int o, const int nr) {
  23. switch (o) {
  24. case N: x -= nr; break;
  25. case E: y += nr; break;
  26. case S: x += nr; break;
  27. case V: y -= nr; break;
  28. default: break; // unreachable
  29. }
  30. }
  31.  
  32. void zbr(int& l, int& c, const int nr, const int n) {
  33. l = nr / n;
  34. c = rest(nr, n);
  35. }
  36.  
  37. int main() {
  38. ifstream fin("pelican.in");
  39. ofstream fout("pelican.out");
  40. int n, p, k, x, y, o, last_z, l_aft_z, c_aft_z, total_rot;
  41.  
  42. fin >> n >> p >> k;
  43. for (int i = 0; i < p; ++i) {
  44. fin >> rate[i].l >> rate[i].c >> rate[i].o;
  45. --rate[i].o;
  46. }
  47.  
  48. // daca avem comenzi de Z nu mai conteaza pos initiala,
  49. // doar unde am ajuns dupa Z
  50. last_z = -1;
  51. for (int i = 0; i < k; ++i) {
  52. fin >> queries[i].com >> queries[i].nr;
  53. if (queries[i].com == 'Z') last_z = i;
  54. }
  55.  
  56. // inainte de Z conteaza doar comenzile R
  57. total_rot = 0;
  58. if (last_z >= 0) {
  59. zbr(l_aft_z, c_aft_z, queries[last_z].nr, n);
  60. for (int i = 0; i < last_z; ++i)
  61. if (queries[i].com == 'R')
  62. total_rot += queries[i].nr;
  63. }
  64.  
  65. // simulez comenzi cu rata "virtuala" din (0, 0) cu orientarea N
  66. x = y = o = 0;
  67. for (int i = last_z + 1; i < k; ++i) {
  68. if (queries[i].com == 'R') o = (o + queries[i].nr) % 4;
  69. else if (queries[i].com == 'A') adv(x, y, o, queries[i].nr);
  70. }
  71.  
  72. x %= n; y %= n;
  73.  
  74. for (int i = 0; i < p; ++i) {
  75. if (last_z >= 0) {
  76. rate[i].l = l_aft_z;
  77. rate[i].c = c_aft_z;
  78. rate[i].o = (rate[i].o + total_rot) % 4;
  79. }
  80.  
  81. // aflu poz finala in functie de cea a ratei virtuale
  82. switch (rate[i].o) {
  83. case N:
  84. fout << rest(rate[i].l + x, n) << ' ' << rest(rate[i].c + y, n) << '\n'; break;
  85. case E:
  86. fout << rest(rate[i].l + y, n) << ' ' << rest(rate[i].c - x, n) << '\n'; break;
  87. case S:
  88. fout << rest(rate[i].l - x, n) << ' ' << rest(rate[i].c - y, n) << '\n'; break;
  89. case V:
  90. fout << rest(rate[i].l - y, n) << ' ' << rest(rate[i].c + x, n) << '\n'; break;
  91. default: break; // unreachable
  92. }
  93. }
  94.  
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement