Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef pair<int, int>P;
  5.  
  6. bool cmp(P f, P s){
  7. if(f.first > s.first) return 0;
  8. if(f.first == s.first){
  9. if(f.second > s.second) return 0;
  10. else return 1;
  11. }else return 1;
  12. }
  13.  
  14. int main()
  15. {
  16. int casee;
  17. cin >> casee;
  18. while(casee--)
  19. {
  20. int n;
  21. char str[1000000];
  22. int c=0;
  23. cin >> n;
  24. vector< pair<int, int> > vec;
  25. for(int i = 0; i < n; i++)
  26. {
  27. int x, y;
  28. cin >> x >> y;
  29. vec.push_back(make_pair(x, y));
  30. }
  31. sort(vec.begin(), vec.end(), cmp);
  32.  
  33. int xx=0,yy=0,d=0,ck=0;
  34.  
  35. for(int i=0;i<n;i++)
  36. {
  37. int x,y;
  38. x = vec[i].first;
  39. y = vec[i].second;
  40.  
  41. if(x<xx)
  42. {
  43. ck=1;
  44. break;
  45. }
  46. if(y<yy)
  47. {
  48. ck=1;
  49. break;
  50. }
  51. if(xx<x)
  52. {
  53. int h=x-xx;
  54. while(h--)
  55. {
  56. str[c++] = 'R';
  57. }
  58. xx=x;
  59. }
  60.  
  61. if(x==xx)
  62. {
  63. if(yy>y)
  64. {
  65. ck=1;
  66. break;
  67. }
  68. else{
  69. int h=y-yy;
  70. while(h--)
  71. {
  72. str[c++] = 'U';
  73. }
  74. yy=y;
  75. }
  76. }
  77. }
  78.  
  79. str[c]='\0';
  80. if(ck==1)
  81. {
  82. cout<<"NO"<<endl;
  83. }
  84. else{
  85. cout<<"YES"<<endl;
  86. cout<<str<<endl;
  87. }
  88. }
  89. return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement