Robots Easy (Gym-102267D)

Problem Description

Alice was playing her favorite game, "Tales of the Abyss", while playing she encountered the following puzzle that can be described as a 12×12 grid:

A robot is standing somewhere in this grid, you can order the robot to move up, down, right or left. The robot can't move to a blocked cell(fully black cell), but it can move to other cells(white and crossed cells). If you order the robot to move to a blocked cell or to move outside the grid then the robot won't move.

The goal of the puzzle is to move the robot to a crossed cell in at most 1000 moves. You will be given the description of some levels of this puzzle that Alice has solved, can you solve them too?

Input

In the first line you will be given the integer L(1≤L≤134), the number of levels you need to solve.

Then you will be given L lines describing the levels, each line will contain two integers r,c(1≤r,c≤12), the row and column of the cell the robot is currently standing at, it's guaranteed that this cell is not a blocked cell(not a fully black cell). The rows are numbered from top(1) to bottom(12), and columns are numbered from left(1) to right(12).

Output

For each level output exactly 2 lines, the first line containing a single integer n(0≤n≤1000), representing the number of moves you want to make, and the second line a string of length nn made of the letters 'U','D','R' and 'L'(upper_case) meaning Up, Down, Right and Left describing the moves.

Please note that in order to get accepted you have to follow the above format exactly, printing the number of moves and the string on the same line, or printing lower_case letters instead of upper_case for example might give you a wrong answer verdict.

Examples

Input

2
2 3
9 4

Output

4
UUDD
3
LDL

Note

In the first level, the robot moves as follows: (2,3)→(1,3)→(1,3)→(2,3)→(3,3)

In the second level, the robot moves as follows: (9,4)→(9,4)→(10,4)→(10,3)

题意:对于给出的 12*12 的图,有 l 组查询,每组给出一个坐标,要求从这个坐标开始行走,遇到黑色或在边界不能走,直到遇到星号,问要走几步,并给出行走方案,要求步数不超过 1000,输出任意方案

思路:

bfs 裸题,但可以模拟来做

由于步数不超过 1000 且可以输出任意方案,那么对于任意一个点,只要让其走到左下角,然后向右两步再向上两步一定有解

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
const int MOD = 1E9+7;
const int N = 20+5;
const int dx[] = {1,-1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int main() {
    int l;
    scanf("%d",&l);
    for(int i=1;i<=l;i++){
        int r1,c1;
        scanf("%d%d",&r1,&c1);
        printf("40\n");
        //向下12步,向左12步,再向下12步一定可以走到右下角
        for(int i=1;i<=12;i++)
            printf("D");
        for(int i=1;i<=12;i++)
            printf("L");
        for(int i=1;i<=12;i++)
            printf("D");

        printf("RRUU\n");//向右2步向上2步
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值