#include #include #include #include #include #include #include void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { //printf("%d %d %d %d\n", i_start, j_start, i_end, j_end); int i = 0, j = 0, flag_i = 0; //flag ON if impossible char arr_moves[1000][3]; int abs_y_diff = (i_start>i_end) ? (i_start-i_end) : (i_end-i_start); int abs_x_diff = (j_start>j_end) ? (j_start-j_end) : (j_end-j_start); //printf("%d %d\n", abs_y_diff, abs_x_diff); if(abs_y_diff%2 == 1) flag_i = 1; if((abs_y_diff/2)%2 == 1 && (abs_x_diff)%2 == 0) flag_i = 1; if((abs_y_diff/2)%2 == 0 && (abs_x_diff)%2 == 1) flag_i = 1; if(flag_i == 1) { printf("Impossible\n"); return; } while(i_start!=i_end || j_start!=j_end) { //printf("A\n"); if(i_end < i_start && j_end > j_start) { arr_moves[i][0] = 'U'; arr_moves[i][1] = 'R'; arr_moves[i][2] = '\0'; i++; i_start = i_start - 2; j_start = j_start + 1; } else if(i_end == i_start && j_end > j_start) { arr_moves[i][0] = 'R'; arr_moves[i][1] = '\0'; i++; j_start = j_start + 2; } else if(i_end > i_start && j_end > j_start) { if(j_end-j_start > 2) { arr_moves[i][0] = 'R'; arr_moves[i][1] = '\0'; i++; j_start = j_start + 2; } else { arr_moves[i][0] = 'L'; arr_moves[i][1] = 'R'; arr_moves[i][2] = '\0'; i++; i_start = i_start + 2; j_start = j_start + 1; } } else if(i_end > i_start && j_end == j_start) { arr_moves[i][0] = 'L'; arr_moves[i][1] = 'R'; arr_moves[i][2] = '\0'; i++; i_start = i_start + 2; j_start = j_start + 1; } else if(i_end > i_start && j_end < j_start) { arr_moves[i][0] = 'L'; arr_moves[i][1] = 'L'; arr_moves[i][2] = '\0'; i++; i_start = i_start + 2; j_start = j_start - 1; } else if(i_end == i_start && j_end < j_start) { arr_moves[i][0] = 'L'; arr_moves[i][1] = '\0'; i++; j_start = j_start - 2; } else if(i_end < i_start && j_end < j_start) { //printf("B\n"); arr_moves[i][0] = 'U'; arr_moves[i][1] = 'L'; arr_moves[i][2] = '\0'; //printf("C\n"); i++; i_start = i_start - 2; j_start = j_start - 1; //printf("%d %d %d %d\n", i_start, j_start, i_end, j_end); } else if(i_end < i_start && j_end == j_start) { arr_moves[i][0] = 'U'; arr_moves[i][1] = 'L'; arr_moves[i][2] = '\0'; i++; i_start = i_start - 2; j_start = j_start - 1; } } printf("%d\n", i); for(j = 0; j < i; j++) { printf("%s ", arr_moves[j]); } return; } int main() { int n; scanf("%i", &n); int i_start; int j_start; int i_end; int j_end; scanf("%i %i %i %i", &i_start, &j_start, &i_end, &j_end); printShortestPath(n, i_start, j_start, i_end, j_end); return 0; }