Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- static const int MAXP = 10000, MAXK = 100000, MAXCHAR = 128;
- static const int N = 0, E = 1, S = 2, V = 3;
- struct Rata {
- int l, c, o;
- } virtuale[4], rate[MAXP];
- struct Query {
- char com;
- int nr;
- } queries[MAXK];
- // pt modulo negativ din c/c++
- int rest(const int a, const int b) {
- int retval = a % b;
- return retval >= 0 ? retval : retval + b;
- }
- void adv(int& x, int& y, const int o, const int nr) {
- switch (o) {
- case N: x -= nr; break;
- case E: y += nr; break;
- case S: x += nr; break;
- case V: y -= nr; break;
- default: break; // unreachable
- }
- }
- void zbr(int& l, int& c, const int nr, const int n) {
- l = nr / n;
- c = rest(nr, n);
- }
- int main() {
- ifstream fin("pelican.in");
- ofstream fout("pelican.out");
- int n, p, k, x, y, o, last_z, l_aft_z, c_aft_z, total_rot;
- fin >> n >> p >> k;
- for (int i = 0; i < p; ++i) {
- fin >> rate[i].l >> rate[i].c >> rate[i].o;
- --rate[i].o;
- }
- // daca avem comenzi de Z nu mai conteaza pos initiala,
- // doar unde am ajuns dupa Z
- last_z = -1;
- for (int i = 0; i < k; ++i) {
- fin >> queries[i].com >> queries[i].nr;
- if (queries[i].com == 'Z') last_z = i;
- }
- // inainte de Z conteaza doar comenzile R
- total_rot = 0;
- if (last_z >= 0) {
- zbr(l_aft_z, c_aft_z, queries[last_z].nr, n);
- for (int i = 0; i < last_z; ++i)
- if (queries[i].com == 'R')
- total_rot += queries[i].nr;
- }
- // simulez comenzi cu rata "virtuala" din (0, 0) cu orientarea N
- x = y = o = 0;
- for (int i = last_z + 1; i < k; ++i) {
- if (queries[i].com == 'R') o = (o + queries[i].nr) % 4;
- else if (queries[i].com == 'A') adv(x, y, o, queries[i].nr);
- }
- x %= n; y %= n;
- for (int i = 0; i < p; ++i) {
- if (last_z >= 0) {
- rate[i].l = l_aft_z;
- rate[i].c = c_aft_z;
- rate[i].o = (rate[i].o + total_rot) % 4;
- }
- // aflu poz finala in functie de cea a ratei virtuale
- switch (rate[i].o) {
- case N:
- fout << rest(rate[i].l + x, n) << ' ' << rest(rate[i].c + y, n) << '\n'; break;
- case E:
- fout << rest(rate[i].l + y, n) << ' ' << rest(rate[i].c - x, n) << '\n'; break;
- case S:
- fout << rest(rate[i].l - x, n) << ' ' << rest(rate[i].c - y, n) << '\n'; break;
- case V:
- fout << rest(rate[i].l - y, n) << ' ' << rest(rate[i].c + x, n) << '\n'; break;
- default: break; // unreachable
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement