zoukankan      html  css  js  c++  java
  • 牛客训练四:Applese 走方格(细节)

    题目链接:传送门

    思路:主要是n=1,m=2或者n=2,m=1时,不是-1。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main(void)
    {
        int n,m,i,j;
        while(~scanf("%d%d",&n,&m)){
            if(n==1){
                if(m==2) printf("RL");
                else printf("-1");
            }
            else if(m==1){
                if(n==2) printf("DU");
                else printf("-1");
            }
            else if(n%2==1&&m%2==1){
                printf("-1");
            }
            else if(m%2==0){
                for(i=0;i<m-1;i++) printf("R");printf("D");
                for(i=m;i>=1;i--){
                    if(i%2==0){
                        for(j=1;j<=n-2;j++) printf("D");printf("L");
                    }
                    else{
                        for(j=1;j<=n-2;j++) printf("U");
                        if(i==1) printf("U");
                        else printf("L");
                    }
                }
            }
            else if(n%2==0){
                for(i=0;i<n-1;i++) printf("D");printf("R");
                for(i=n;i>=1;i--){
                    if(i%2==0){
                        for(j=1;j<=m-2;j++) printf("R");printf("U");
                    }
                    else{
                        for(j=1;j<=m-2;j++) printf("L");
                        if(i==1) printf("L");
                        else printf("U");
                    }
                }
            }
            printf("
    ");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    [Postman]历史(8)
    [Postman]响应(7)
    [Postman]请求(6)
    [Postman]查找替换(5)
    ORA-02050故障诊断一例
    转 js实践篇:例外处理Try{}catch(e){}
    转 PHP
    HTML DOM getElementById() 方法
    地点选择
    9i 和 11 g 区别
  • 原文地址:https://www.cnblogs.com/2018zxy/p/10335443.html
Copyright © 2011-2022 走看看