Robots Hard(Gym-102267E)

Problem Description

Notice that you need to read the statement of "D. Robots Easy" in order to understand this problem.

Also notice the unusual 5 megabytes memory limit.

Alice now is trying to beat the harder version of this puzzle, the only difference from the easy version is that there are 4 robots instead of 1, when ordering the robots to move in a specific direction, all 4 robots move at the same time(that is you can't order a single robot to move).

If the cell the robot should move to is blocked, then the robot doesn't move, if it's empty or crossed then it does move, if the cell already has another robot standing in it then if that robot in that cell is moving then the current robot will also move, otherwise it will not move.

For example if there's a robot in cell (1,1) and another in cell (1,2) and you order the robots to move to the left, then both of these robots won't move, but if there's a robot in cell (1,2) and another in cell (1,3) and you order the robots to move to the left then both robots will move to the left.

In order to beat the level you need to move the robots such that in the end each robot is standing in a crossed cell. Alice couldn't solve any of the hard levels, can you solve them with at most 1000 moves for a level?

Input

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

Then you will be given LL lines describing the levels, each line will contain eight integers r1,c1,r2,c2,r3,c3,r4,c4(1≤ri,ci≤12,1≤i≤4), the positions of the robots, it's guaranteed that none of the cells are blocked cells and all four cells are distinct.

Output

The output is the same as the easy version.

Examples

Input

1
4 2 4 9 11 2 10 10

Output

2
RU

题意:是 Robots Easy (Gym-102267D)的加强版,在原来的基础上,由一个机器人变成四个机器人,四个机器人移动方向永远相同,除非遇到阻碍,且四个机器人不会走到一个格子上,会堆叠在一起

思路:考虑 Robots Easy (Gym-102267D)的做法,首先走到最左下角排成一行,然后再转为左下角的一列,最后向外扩,具体过程见下图

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 = 10000000+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 t;
	scanf("%d",&t);
	while (t--){
        int r1,c1,r2,c2,r3,c3,r4,c4;
        scanf("%d%d%d%d%d%d%d%d",&r1,&c1,&r2,&c2,&r3,&c3,&r4,&c4);

        string res;

        //变成左下角的一行
        for(int i=1;i<=12;i++)
            res+="D";
        for(int i=1;i<=12;i++)
            res+="L";
        for(int i=1;i<=12;i++)
            res+="D";

        //转为左下角的一列
        for(int i=1;i<=4;i++){
            res+="UUUUU";
            res+="LL";
            res+="DDDDD";
            res+="L";
            res+="DDDDD";
        }
        res+="RRRRRRRR";
        res+="DD";
        res+="UUU";
        res+="R";
        res+="DDDD";
        res+="UUUUU";
        res+="LL";
        res+="DDDD";
        res+="RR";
        res+="UUUU";

        printf("%d\n", res.size());
        cout<<res<<endl;
	}
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值