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×m. Initially, k chips are placed on the board, i-th chip is located in the cell at the intersection of sxi-th row and syi-th column.
In one action, Petya can move all the chips to the left, right, down or up by 1 cell.
If the chip was in the (x,y) cell, then after the operation:
left, its coordinates will be (x,y−1);
right, its coordinates will be (x,y+1);
down, its coordinates will be (x+1,y);
up, its coordinates will be (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 2nm 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 2nm actions.
Input
The first line contains three integers n,m,k (1≤n,m,k≤200) — the number of rows and columns of the board and the number of chips, respectively.
The next k lines contains two integers each sxi,syi (1≤sxi≤n,1≤syi≤m) — the starting position of the i-th chip.
The next k lines contains two integers each fxi,fyi (1≤fxi≤n,1≤fyi≤m) — the position that the i-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,U respectively.
If the required sequence does not exist, print -1 in the single line.
Examples
input
3 3 2
1 2
2 1
3 3
3 2
output
3
DRD
input
5 4 3
3 4
3 1
3 3
5 3
1 3
1 4
output
9
DDLUUUURR
C.筹码游戏
每次测试的时限1秒
每个测试的内存限制256 MB
输入标准输入
输出标准输出
Petya具有大小为n×m的矩形板。最初,将k个芯片放置在板上,第i个芯片位于单元中的第sxi行和syi-th列相交处。
在一次动作中,Petya可以将所有筹码向左,向右,向下或向上移动1个单元。
如果芯片在(x,y)单元中,则在操作之后:
左,其坐标将为(x,y−1);
正确,其坐标将为(x,y + 1);
向下,其坐标将为(x + 1,y);
向上,其坐标将为(x-1,y)。
如果芯片位于板壁的旁边,并且Petya选择的动作将其移向壁,则芯片将保持在其当前位置。
请注意,几个芯片可以位于同一单元中。
Petya为每个芯片选择了应该访问的位置。请注意,芯片不必最终停留在该位置。
由于Petya没有太多的空闲时间,因此他准备做的动作不超过2nm。
您必须找出Petya应该采取的行动,以便每个筹码至少访问一次Petya为其选择的位置。或确定不可能在2nm动作中执行此操作。
输入值
第一行包含三个整数n,m,k(1≤n,m,k≤200)-电路板的行数和列数以及芯片数。
接下来的k行包含两个整数,每个sxi,syi(1≤sxi≤n,1≤syi≤m)—第i个芯片的起始位置。
接下来的k行包含两个整数,每个整数fxi,fyi(1≤fxi≤n,1≤fyi≤m)— i芯片应至少访问一次的位置。
输出量
在第一行中,打印操作数,以便每个芯片至少访问一次Petya为其选择的位置。
在第二行输出操作顺序。要指示左,右,下和上的操作,请分别使用字符L,R,D,U。
如果所需的序列不存在,则在单行中打印-1。
例子
input
3 3 2
1 2
2 1
3 3
3 2
output
3
DRD
input
5 4 3
3 4
3 1
3 3
5 3
1 3
1 4
output
9
DDLUUUURR
题目大意:输入n,m,k 给出n x m大小的空间,然后接下来有2*k行,表示第 i 行的点要在2nm步之内访问到 i + k 行的点,求k-2k行的点全部访问后的步数以及操作方向。
但是题目里说了移动次数只要不超过2nm就可以
2 n m ? 把 所 有 点 走 一 遍 不 过 n m , 剩 下 n m 把 所 有 点 移 到 最 左 上 角 , 然 后 一 排 一 排 S 型 走
#include
using namespace std;
#define int long long
#define endl '\n'
#define YES cout<<"YES"< PII;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
const int N = 1e5+10;
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
void solve()
{
int n,m,k;
cin>>n>>m>>k;
int maxx=0;int minn=0;
for(int i=1;i<=k;i++)
{
int x,y;
cin>>x>>y;
maxx=max(maxx,x);
minn=max(minn,y);
}
int ans=minn+maxx-2;
for(int i=1;i<=k;i++)
{
int x,y;
cin>>x>>y;
}
string s="";
for(int i=1;i