zoukankan      html  css  js  c++  java
  • CF 1294B-Collecting Packages

    题目:https://vjudge.net/problem/CodeForces-1294B#author=tjrac6018203068

    分析:用结构体存储每个包裹的坐标,然后按照横、纵坐标从小到大排序,然后遍历一遍,因为要字典序最小,故优先向右走,遍历过程中更新robot坐标,如果当前包裹的纵坐标比robot小,因为只能向上或者向右走,说明无法收集所有包裹。

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 struct node{
     4     int x;
     5     int y;
     6 }s[1010];
     7 int cmp(const void*a,const void*b){
     8     if((*(node*)a).x!=(*(node*)b).x)
     9     return (*(node*)a).x-(*(node*)b).x;
    10     else return (*(node*)a).y-(*(node*)b).y;
    11 }
    12 int main(void){
    13     int t;
    14     scanf("%d",&t);
    15     while(t--){
    16         int n;
    17         scanf("%d",&n);
    18         for(int i=0;i<n;i++){
    19             scanf("%d %d",&s[i].x,&s[i].y);
    20         }
    21         qsort(s,n,sizeof(node),cmp);
    22         int h=0;
    23         char c[1000000]={''};
    24         int x1=0,y1=0;
    25         int b=0;
    26         for(int i=0;i<n;i++){
    27             if(s[i].x>x1){
    28                 for(int j=1;j<=s[i].x-x1;j++){
    29                     c[h]='R';
    30                     h++;
    31                 }
    32                 x1=s[i].x;
    33             }
    34             if(s[i].y>y1){
    35                 for(int j=1;j<=s[i].y-y1;j++){
    36                     c[h]='U';
    37                     h++;
    38                 }
    39                 y1=s[i].y;
    40             }
    41             if(s[i].y<y1){
    42                 b=1;
    43                 break;
    44             }
    45         }
    46         if(b==1)printf("NO
    ");
    47         else{
    48             printf("YES
    ");
    49             printf("%s
    ",c);
    50         }
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    1.Apache与Tomcat
    jeeplus 多选框
    GIT 回滚
    jsp 中data 转换 字符串
    Pattern和Matcher中表达式
    web.xml 详细介绍
    $.ajax()方法详解
    My 2016
    如何做好一个保安队长。
    集合之WeakHashMap
  • 原文地址:https://www.cnblogs.com/yanying7/p/12323028.html
Copyright © 2011-2022 走看看