AtCoder Regular Contest 103 D - Robot Arms

D - Robot Arms


Time limit : 2sec / Memory limit : 1024MB

Score : 600 points

Problem Statement

Snuke is introducing a robot arm with the following properties to his factory:

  • The robot arm consists of m sections and m+1 joints. The sections are numbered 1, 2, ..., m, and the joints are numbered 0, 1, ..., m. Section i connects Joint i−1 and Joint i. The length of Section i is di.
  • For each section, its mode can be specified individually. There are four modes: LRD and U. The mode of a section decides the direction of that section. If we consider the factory as a coordinate plane, the position of Joint i will be determined as follows (we denote its coordinates as (xi,yi)):
    • (x0,y0)=(0,0).
    • If the mode of Section i is L, (xi,yi)=(xi−1−di,yi−1).
    • If the mode of Section i is R, (xi,yi)=(xi−1+di,yi−1).
    • If the mode of Section i is D, (xi,yi)=(xi−1,yi−1−di).
    • If the mode of Section i is U, (xi,yi)=(xi−1,yi−1+di).

Snuke would like to introduce a robot arm so that the position of Joint m can be matched with all of the N points (X1,Y1),(X2,Y2),…,(XN,YN) by properly specifying the modes of the sections. Is this possible? If so, find such a robot arm and how to bring Joint m to each point (Xj,Yj).

Constraints

  • All values in input are integers.
  • 1≤N≤1000
  • −109≤Xi≤109
  • −109≤Yi≤109

Partial Score

  • In the test cases worth 300 points, −10≤Xi≤10 and −10≤Yi≤10 hold.

Input

Input is given from Standard Input in the following format:

N
X1 Y1
X2 Y2
:
XN YN

Output

If the condition can be satisfied, follow the following format. If the condition cannot be satisfied, print -1.

m
d1 d2 … dm
w1
w2
:
wN

m and di are the configurations of the robot arm. Refer to the problem statement for what each of them means. Here, 1≤m≤40 and 1≤di≤1012 must hold. Also, m and di must all be integers.

wj is a string of length m that represents the way to bring Joint m of the robot arm to point (Xj,Yj). The i-th character of wj should be one of the letters LRD and U, representing the mode of Section i.


Sample Input 1

Copy

3
-1 0
0 3
2 -1

Sample Output 1

Copy

2
1 2
RL
UU
DR

In the given way to bring Joint m of the robot arm to each (Xj,Yj), the positions of the joints will be as follows:

  • To (X1,Y1)=(−1,0): First, the position of Joint 0 is (x0,y0)=(0,0). As the mode of Section 1 is R, the position of Joint 1 is (x1,y1)=(1,0). Then, as the mode of Section 2 is L, the position of Joint 2 is (x2,y2)=(−1,0).
  • To (X2,Y2)=(0,3): (x0,y0)=(0,0),(x1,y1)=(0,1),(x2,y2)=(0,3).
  • To (X3,Y3)=(2,−1): (x0,y0)=(0,0),(x1,y1)=(0,−1),(x2,y2)=(2,−1).

Sample Input 2

Copy

5
0 0
1 0
2 0
3 0
4 0

Sample Output 2

Copy

-1

Sample Input 3

Copy

2
1 1
1 1

Sample Output 3

Copy

2
1 1
RU
UR

There may be duplicated points among (Xj,Yj).


Sample Input 4

Copy

3
-7 -3
7 3
-3 -7

Sample Output 4

Copy

5
3 1 4 1 5
LRDUL
RDULR
DULRD

 

题解和题意戳这:

https://blog.csdn.net/zxyoi_dreamer/article/details/82905515

https://blog.csdn.net/Mr_Treeeee/article/details/82913309

AtCoder上的题都好神呀QAQ。。。

自己还是太弱了QAQ

挂一下程序:

#include
#define INF 0x7fffffff
#define LL long long
using namespace std;
LL fx[5]={-1,1,0,0};
LL fy[5]={0,0,-1,1};
LL x[1010],y[1010],cc[50];
char Fx[5]={'L','R','D','U'};
LL read()
{
	LL s=0,fh=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+(ch-'0');ch=getchar();}
	return s*fh;
}
LL DIS(LL xx1,LL yy1,LL xx2,LL yy2){return (LL)fabs(xx2-xx1)+(LL)fabs(yy2-yy1);}
int main()
{
	LL i,xx,yy,xx1,yy1,n,s,lcc,mn,jj,k,j,dis;
	bool js,os;
	n=read();
	js=os=false;
	for(i=1;i<=n;i++){x[i]=read();y[i]=read();s=(LL)fabs(x[i])+(LL)fabs(y[i]);if(s%2LL==0LL)os=true;else js=true;}
	if(js==true&&os==true){printf("-1");return 0;}
	else
	{
		lcc=0LL;for(i=30LL;i>=0LL;i--)cc[++lcc]=(1LL<

 

你可能感兴趣的:(ACM,思路题,二进制拆分,构造)