[ABC326 F] Robot Rotation
Genius_Star · · 题解
题意:
机器人位于坐标平面的原点,其中正
最初,机器人面向正
您将按以下顺序对
将机器人顺时针或逆时针旋转
是否可以选择旋转方向,使机器人在
如果可能,确定每次操作应选择顺时针或逆时针方向。
思路:
因为
直接爆搜是
因为每次操作,都是按照
那么,这样两者分开爆搜的话,时间复杂度为
考虑对于
那么先爆搜出
对于每一种可能的值算一下还需要增加多少才可以到达目标值
时间复杂度为:
注意一下:最后输出答案的时候,对于每次
完整代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=805,M=2000200;
inline ll read(){
ll x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')
f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x*f;
}
inline void write(ll x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}
struct Node{
ll x;
string s;
bool operator<(const Node&rhs)const{
return x<rhs.x;
}
}d[M];
ll n,x,y,k,l1,l2,cnt=0;
ll a[N],b[N];
string t;
string ans[2];
bool F[2];
void dfs(ll* a,ll l,ll r,ll x,ll y,bool f,bool k){
if(l==(r+1)){
if(!f)
d[++cnt]={x,t};
else{
Node p={y-x,""};
ll h=lower_bound(d+1,d+cnt+1,p)-d;
if(d[h].x==y-x){
ans[k]=d[h].s+t;
F[k]=1;
}
}
return ;
}
t.push_back('+');
dfs(a,l+1,r,x+a[l],y,f,k);
t.pop_back();
t.push_back('-');
dfs(a,l+1,r,x-a[l],y,f,k);
t.pop_back();
}
int main(){
n=read(),x=read(),y=read();
for(int i=1;i<=n;i++){
k=read();
if(i&1)
a[++l1]=k;
else
b[++l2]=k;
}
dfs(a,1,l1/2,0,y,0,0);
sort(d+1,d+cnt+1);
dfs(a,l1/2+1,l1,0,y,1,0);
cnt=0;
dfs(b,1,l2/2,0,x,0,1);
sort(d+1,d+cnt+1);
dfs(b,l2/2+1,l2,0,x,1,1);
if(F[0]&&F[1]){
puts("Yes");
ll c1=0,c2=0,t=0;
for(int i=1;i<=n;i++){
if(i&1){
if(ans[0][c1]=='+'){
putchar(t==0?'L':'R');
t=3;
}
else{
putchar(t==0?'R':'L');
t=1;
}
c1++;
}
else{
if(ans[1][c2]=='+'){
putchar(t==3?'R':'L');
t=0;
}
else{
putchar(t==3?'L':'R');
t=2;
}
c2++;
}
}
}
else
puts("No");
return 0;
}