Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <math.h>
- using namespace std;
- struct Coordinates
- {
- int x;
- int y;
- };
- void qsort(Coordinates*& c, int b, int e)
- {
- int l = b, r = e;
- double piv = sqrt((c[(l + r) / 2].x) * (c[(l + r) / 2].x) + (c[(l + r) / 2].y) * (c[(l + r) / 2].y));
- while (l <= r)
- {
- while (sqrt((c[l].x) * (c[l].x) + (c[l].y) * (c[l].y)) < piv)
- l++;
- while (sqrt((c[r].x) * (c[r].x) + (c[r].y) * (c[r].y)) > piv)
- r--;
- if (l <= r)
- {
- Coordinates temp;
- temp.x = c[l].x;
- temp.y = c[l].y;
- c[l].x = c[r].x;
- c[l].y = c[r].y;
- c[r].x = temp.x;
- c[r].y = temp.y;
- l++;
- r--;
- }
- }
- if (b < r)
- qsort(c, b, r);
- if (e > l)
- qsort(c, l, e);
- }
- int main()
- {
- int t, x, y, rx, ry, n = 0;
- cin >> t;
- string s = "", res = "";
- Coordinates* c = nullptr;
- int j;
- while (t-- > 0)
- {
- cin >> n;
- c = new Coordinates[n];
- for (int i = 0; i < n; i++)
- {
- cin >> c[i].x >> c[i].y;
- }
- x = y = 0;
- qsort(c, 0, n - 1);
- for (j = 0; j < n; j++)
- {
- if (x <= c[j].x && y <= c[j].y)
- {
- rx = c[j].x - x;
- ry = c[j].y - y;
- if (rx == ry)
- {
- for (int i = 0; i < rx; i++)
- s += 'R';
- for (int i = 0; i < rx; i++)
- s += 'U';
- }
- else
- {
- if (rx < ry)
- {
- if (rx == 0)
- {
- for (int i = 0; i < ry; i++)
- s += 'U';
- }
- else
- {
- for (int i = 0; i < rx; i++)
- s += 'R';
- for (int i = 0; i < ry; i++)
- s += 'U';
- }
- }
- else
- {
- if (ry == 0)
- for (int i = 0; i < rx; i++)
- s += 'R';
- else
- {
- for (int i = 0; i < rx; i++)
- s += 'R';
- for (int i = 0; i < ry; i++)
- s += 'U';
- }
- }
- }
- x = c[j].x;
- y = c[j].y;
- }
- else
- {
- s = "";
- res = res + "NO ";
- //cout << no << "\n";
- break;
- }
- }
- if (j == n)
- {
- res += "YES " + s + " ";
- //cout << yes << "\n";
- //cout << s << "\n";
- s = "";
- }
- delete[]c;
- }
- for (int i = 0; i < res.length(); i++)
- {
- if (res[i] == ' ')
- cout << "\n";
- else cout << res[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment