Smzzl with Greedy Snake
贪心在当前吃完的地方直接直线+转弯+直线的方式吃掉下一个
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
#define ll long long
#define lowbit(x) x&-x
//typedef __int128 ll;
typedef pair<int,int>pll;
const int mod=1e9+7;
double pi=acos(-1);
string way1(int x, int y, int &d, int sx, int sy){
string s1="";
if(sx<x && d!=3){
if(d==0)s1+='u';
if(d==2)s1+='c';
if(d==1)s1+="uu";
d=3;
}
if(sx>x && d!=1){
if(d==0)s1+='c';
if(d==2)s1+='u';
if(d==3)s1+="uu";
d=1;
}
s1 += string(abs(sx-x), 'f');
if(sy<y && d!=2){
if(d==0)s1+="cc";
if(d==1)s1+='c';
if(d==3)s1+='u';
d=2;
}
if(sy>y && d!=0){
if(d==1)s1+='u';
if(d==2)s1+="uu";
if(d==3)s1+='c';
d=0;
}
s1 += string(abs(sy-y), 'f');
return s1;
}
string way2(int x, int y, int &d, int sx, int sy){
string s1="";
if(sy<y && d!=2){
if(d==0)s1+="cc";
if(d==1)s1+='c';
if(d==3)s1+='u';
d=2;
}
if(sy>y && d!=0){
if(d==1)s1+='u';
if(d==2)s1+="uu";
if(d==3)s1+='c';
d=0;
}
s1 += string(abs(sy-y), 'f');
if(sx<x && d!=3){
if(d==0)s1+='u';
if(d==2)s1+='c';
if(d==1)s1+="uu";
d=3;
}
if(sx>x && d!=1){
if(d==0)s1+='c';
if(d==2)s1+='u';
if(d==3)s1+="uu";
d=1;
}
s1 += string(abs(sx-x), 'f');
return s1;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T; cin>>T;
while(T--){
int x, y, d; cin>>x>>y>>d;
int n; cin>>n;
string ans = "";
for(int i = 1; i <= n; i++){
int sx, sy; cin>>sx>>sy;
int d1=d, d2=d;
string t1= way1(x,y,d1,sx,sy);
string t2= way2(x,y,d2,sx,sy);
if(t1.size()<t2.size())ans+=t1,d=d1;
else ans+=t2,d=d2;
x = sx, y = sy;
}
cout<<ans<<"\n";
}
return 0;
}