Gym 101981K - Kangaroo Puzzle - [玄学][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem K]

题目连接:http://codeforces.com/gym/101981/problem/Kc++

Your friend has made a computer video game called “Kangaroo Puzzle” and wants you to give it a tryide

for him. As the name of this game indicates, there are some (at least 2) kangaroos stranded in a puzzlethis

and the player’s goal is to control them to gather. As long as all the kangaroos in the puzzle get together,spa

they can escape the puzzle by the miraculous power of kangaroos.code

The puzzle is a n × m grid consisting of nm cells. There are walls in some cells and the kangaroos cannotblog

enter these cells. The other cells are empty. The kangaroos can move in the following direction: up, down,get

left and right. It is guaranteed that one kangaroo can move from an empty cell to any other. It is alsoinput

guaranteed that there is no cycle in the puzzle — that is, it’s impossible that one kangaroo can move fromstring

an empty cell, pass by several distinct empty cells, and then back to the original cell.it

There is exactly one kangaroo in every empty cell at the beginning. You can control the kangaroos by

pressing the button U, D, L, R on your keyboard. The kangaroos will move simultaneously according to the

button you press. For instance, if you press the button U, a kangaroo would move to the upper cell if it

exists and is empty; otherwise, the kangaroo will stay still. You can press the buttons for at most 50000

times. If there are still two kangaroos standing in different cells after 50000 steps, you will lose the game.

Input

The first line contains two integers, n and m (1 ≤ n, m ≤ 20), the height and the width of the puzzle,

respectively. Each of the next n lines contains a (0,1)-string of length m, representing the puzzle. If the

j-th character of the i+1-th line is 1, then the cell at the i-th row and the j-th column is empty; otherwise

(i.e. it is 0), the corresponding cell is blocked and cannot be entered.

Output

Print a string consisting of U, D, L, R, such that all kangaroos will get together after pressing the buttons

in the order of this string. The length of the string should not exceed 50000. There are many possible

valid answers, so just print any of them.

Examples

standard input

4 4

1111

1001

1001

1110

standard output

LLUUURRRDD

standard input

2 15

111111111111111

101010101010101

standard output

ULLLLLLLLLLLLLL

 

题意:

给出 $n \times m(1 \le n,m \le 20)$ 的迷宫,里面每格 $0$ 表明障碍物,$1$ 表明袋鼠。

如今你有 $L,R,U,D$ 四种操做,能够使得迷宫内全部的袋鼠统一往左/右/上/下移动一格,袋鼠能够重叠,袋鼠遇到障碍物或者边界则不会移动。

如今要求你输出一个长度不超过 $5e4$ 的包含 $L,R,U,D$ 的操做序列,使得最后袋鼠所有集中在某一格上。

 

题解:

由于迷宫的规格很小,因此 $50000$ 次操做,每次操做都随机挑选四个方向中的一个走便可。最后袋鼠所有走到一个格子的几率是很大的。

 

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n,m;
char tmp[23],d[4]={'L','R','U','D'};
int main()
{
    srand(6510561);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",tmp);
    for(int i=1;i<=50000;i++) printf("%c",d[rand()%4]);
}