码迷,mamicode.com
首页 > 其他好文 > 详细

C. Game with Chips

时间:2020-04-11 13:14:22      阅读:62      评论:0      收藏:0      [点我收藏+]

标签:inpu   one   move   font   content   read   dir   double   contain   

C. Game with Chips
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya has a rectangular Board of size n×mn×m. Initially, kk chips are placed on the board, ii-th chip is located in the cell at the intersection of sxisxi-th row and syisyi-th column.

In one action, Petya can move all the chips to the left, right, down or up by 11 cell.

If the chip was in the (x,y)(x,y) cell, then after the operation:

  • left, its coordinates will be (x,y1)(x,y−1);
  • right, its coordinates will be (x,y+1)(x,y+1);
  • down, its coordinates will be (x+1,y)(x+1,y);
  • up, its coordinates will be (x1,y)(x−1,y).

If the chip is located by the wall of the board, and the action chosen by Petya moves it towards the wall, then the chip remains in its current position.

 

Note that several chips can be located in the same cell.

For each chip, Petya chose the position which it should visit. Note that it‘s not necessary for a chip to end up in this position.

Since Petya does not have a lot of free time, he is ready to do no more than 2nm2nm actions.

You have to find out what actions Petya should do so that each chip visits the position that Petya selected for it at least once. Or determine that it is not possible to do this in 2nm2nm actions.

Input

The first line contains three integers n,m,kn,m,k (1n,m,k2001≤n,m,k≤200) — the number of rows and columns of the board and the number of chips, respectively.

The next kk lines contains two integers each sxi,syisxi,syi (1sxin,1syim1≤sxi≤n,1≤syi≤m) — the starting position of the ii-th chip.

The next kk lines contains two integers each fxi,fyifxi,fyi (1fxin,1fyim1≤fxi≤n,1≤fyi≤m) — the position that the ii-chip should visit at least once.

Output

In the first line print the number of operations so that each chip visits the position that Petya selected for it at least once.

In the second line output the sequence of operations. To indicate operations left, right, down, and up, use the characters L,R,D,UL,R,D,U respectively.

If the required sequence does not exist, print -1 in the single line.

Examples
input
Copy
3 3 2
1 2
2 1
3 3
3 2
output
Copy
3
DRD
input
Copy
5 4 3
3 4
3 1
3 3
5 3
1 3
1 4
output
Copy
9
DDLUUUURR

 

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>
//#include <xfunctional>
#define ll  long long
#define PII  pair<int, int>
using namespace std;
int dir[5][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } ,{ 0,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979;
const int mod = 1e9 + 7;
const int maxn = 2005;
//if(x<0 || x>=r || y<0 || y>=c)
//1000000000000000000

inline ll read()
{
    ll x = 0; bool f = true; char c = getchar();
    while (c < 0 || c > 9) { if (c == -) f = false; c = getchar(); }
    while (c >= 0 && c <= 9) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}

int main() 
{
    int n, m, k;
    cin >> n >> m >> k;
    string res="";
    for (int i = 1; i < n; i++)
        res += U;
    for (int i = 1; i < m; i++)
        res += L;
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j < m; j++)
        {
            if (i % 2 == 0)
                res += R;
            else
                res += L;
        }
        if (i != n - 1)
            res += D;
    }
    cout << res.size() << endl;
    cout << res << endl;
    return 0;
}

 

 

C. Game with Chips

标签:inpu   one   move   font   content   read   dir   double   contain   

原文地址:https://www.cnblogs.com/dealer/p/12678612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!