[codeforces 1294B] Collecting Packages 排序+字符串
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址http://codeforces.com/contest/1294/problem/B
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
B - Collecting Packages | GNU C++11 | Accepted | 31 ms | 0 KB |
#include <cstdio>
#include <algorithm>
char out[2010];
using namespace std;
struct node{
int x,y;
}a[1010];
int cmp(node a,node b){
return a.x==b.x?a.y<b.y:a.x<b.x;
}
int main(){
int t,n,i,j,cnt,check;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
sort(a+1,a+1+n,cmp);
cnt=0,check=0;
for(i=1;i<=n;i++)
if(a[i].x>=a[i-1].x&&a[i].y>=a[i-1].y){
for(j=a[i-1].x;j<a[i].x;j++)out[cnt++]='R';
for(j=a[i-1].y;j<a[i].y;j++)out[cnt++]='U';
}
else{
printf("NO\n");
check=1;
break;
}
if(!check)out[cnt]='\0',printf("YES\n%s\n",out);
}
return 0;
}