题解:P12308 [ICPC 2022 WF] 玩具火车轨道
whk 晚自习的时候搓的题。做了差不多十分钟以为自己搓出了最优解实际上 corner case 一筐筐……
很有意思的一道题。很像小时候玩过的一款桌游但记不得名字了。写篇题解记录一下。
我们首先证明,
此时我们不得不至少使用两条直轨道才能用上所有的弯曲轨道了。所以对于直轨道为
考虑
我们仍然考虑扩展这个结构。显然应该往右下方扩展:
可以发现,这样我们每次塞进去
于是做完了。
int s,c;
string ans;
void make40(int s,int c){
if(c==4){
cout<<"RR";
fr1(i,1,s/2) cout<<"S";
cout<<"RR";
fr1(i,1,s/2) cout<<"S";
return;
}
cout<<"R";
fr1(i,1,s/2) cout<<"S";
cout<<"RLR";
fr1(i,1,c/4-2) cout<<"RL";
cout<<"R";
fr1(i,1,s/2) cout<<"S";
cout<<"RLR";
fr1(i,1,c/4-2) cout<<"RL";
}
void make42(int s,int c){
c/=4;
cout<<"RR";
fr1(i,1,c) cout<<"LR";
fr1(i,1,s/2-1) cout<<"S";
cout<<"RSR";
fr1(i,1,s/2-1) cout<<"S";
fr1(i,1,c-1) cout<<"LR";
cout<<"S";
}
int main(){
#ifdef Shun
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
cin>>s>>c;
if(s&1) s--;
if(c&1) c--;
if(c%4==0){
if(c==8){
if(s==0) make40(s,4);
else{
cout<<"RLRRL";
fr1(i,1,s/2-1) cout<<"S";
cout<<"RR";
fr1(i,1,s/2+1) cout<<"S";
cout<<"R";
}
}
else make40(s,c);
}
else{
if(s==0){
if(c==10) make40(s,4);
else make40(s,c-2);
}
else make42(s,c);
}
ET;
}
//ALL FOR Zhang Junhao.