Time limit : 2sec / Memory limit : 1024MB
Score : 600 points
Snuke is introducing a robot arm with the following properties to his factory:
L
, R
, D
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)):
L
, (xi,yi)=(xi−1−di,yi−1).R
, (xi,yi)=(xi−1+di,yi−1).D
, (xi,yi)=(xi−1,yi−1−di).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).
Input is given from Standard Input in the following format:
N X1 Y1 X2 Y2 : XN YN
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 L
, R
, D
and U
, representing the mode of Section i.
Copy
3 -1 0 0 3 2 -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:
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).Copy
5 0 0 1 0 2 0 3 0 4 0
Copy
-1
Copy
2 1 1 1 1
Copy
2 1 1 RU UR
There may be duplicated points among (Xj,Yj).
Copy
3 -7 -3 7 3 -3 -7
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<