#include #include #include #include #include using namespace std; void printShortestPath(vector& sequence, int i_start, int j_start, int i_end, int j_end) { if((abs(i_end - i_start) == 1 && j_start == j_end) || (abs(j_end - j_start) == 1 && i_start == i_end)) { cout << "Impossible"; return; } if(i_start == i_end && j_start == j_end) { cout << sequence.size() << endl; for(int i = 0; i < sequence.size(); i++) cout << sequence[i] << " "; return; } if(i_start > i_end && j_start >= j_end) { sequence.push_back("UL"); printShortestPath(sequence, i_start-2, j_start-1, i_end, j_end); } else if(i_start > i_end && j_start < j_end) { sequence.push_back("UR"); printShortestPath(sequence, i_start-2, j_start+1, i_end, j_end); } else if(i_start == i_end && j_start < j_end) { sequence.push_back("R"); printShortestPath(sequence, i_start, j_start+2, i_end, j_end); } else if(i_start < i_end && j_start <= j_end) { sequence.push_back("LR"); printShortestPath(sequence, i_start+2, j_start+1, i_end, j_end); } else if(i_start < i_end && j_start > j_end) { sequence.push_back("LL"); printShortestPath(sequence, i_start+2, j_start-1, i_end, j_end); } else if(i_start == i_end && j_start > j_end) { sequence.push_back("L"); printShortestPath(sequence, i_start, j_start-2, i_end, j_end); } } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; cin >> n; int i_start, i_end, j_start, j_end; cin >> i_start >> j_start >> i_end >> j_end; vector sequence; printShortestPath(sequence, i_start, j_start, i_end, j_end); return 0; }