A
A
h>
using namespace std;
using db = double;
using T = db;
const db EPS = 1e-9;
using P = pair<T, T>; using vP = V<P>; using Line = pair<P, P>;
int sgn(T a){ return (a > EPS) - (a < -EPS);}
T sq(T a) { return a*a; }
T norm(P p){
return sq(p.f)+sq(p.s);
}
T abs(P p){
return sqrt(norm(p));
}
P operator+(P l, P r){
return P(l.f+r.f, l.s+r.s);
}
P operator-(P l, P r){
return P(l.f-r.f, l.s-r.s);
}
P operator*(P l, T r){
return P(l.f*r, l.s*r);
}
P operator/(P l, T r){
return P(l.f/r, l.s/r);
}
int cache_size[mx][mx];
int not_cached = 0;
void getAllIsects(pi pos_second){
assert(pos_second.f >= pos_second.s && 0 <= pos_second.f && 0 <= pos_second.s);
// if(cache_all_isects.count(pos_second)) return cache_all_isects[pos_second.f]
[pos_second.s];
db slop = pos_second.s/pos_second.f;
db tot_dist = abs(l.s-l.f);
isect_point = upper_right;
next_point.f++;
next_point.s++;
}
else if(SGN == 1){ // go right
db x = cur_point.f+0.5;
isect_point = mp(x, slop*x);
next_point.f++;
}
else if(SGN == -1){
// Line horz = mp(mp(cur_point.f-0.5, cur_point.s+0.5),
mp(cur_point.f+0.5, cur_point.s+0.5));
//y = cur_point.s+0.5
db y = cur_point.s+0.5;
isect_point = mp(y/slop, y);
next_point.s++;
}
db dist = abs(isect_point-l.f);
db frac = dist/tot_dist;
cache_all_isects[pos_second.f][pos_second.s][cache_size[pos_second.f]
[pos_second.s]] = mp(cur_point, frac);
cache_size[pos_second.f][pos_second.s]++;
cache_all_isects[pos_second.f][pos_second.s][cache_size[pos_second.f]
[pos_second.s]] = mp(next_point, frac);
cache_size[pos_second.f][pos_second.s]++;
cur_point = next_point;
// cout << pos_second_normalized.f << " " << pos_second_normalized.s << "\n";
cout.flush();
// assert(cache_all_isects.count(pos_second_normalized));
if(DEBUG){
R1 = 1;
C1 = 1;
R2 = P;
C2 = Q;
}
else{
cin >> R1 >> C1 >> R2 >> C2;
}
queue<pair<int, pi>> q;
ckmin(dist[R1][C1], 0);
q.push(mp(dist[R1][C1], mp(R1, C1)));
while(sz(q)){
int dis = q.front().f;
pi pos = q.front().s;
// cout << pos.f << " " << pos.s << " " << dis << "\n";
q.pop();
assert(1 <= pos.f && pos.f <= P && 1 <= pos.s && pos.s <= Q);
if(dist[pos.f][pos.s] < dis) continue;
if(ckmin(dist[new_x][new_y], dis+1)){
// cout << "CKMIN: " << new_x << " " << new_y << " " << d+1 << "\
n";
// cout << "CUR HEIGHT: " << Z[pos.f][pos.s] << "\n";
// cout << "HEIGHT: " << Z[new_x][new_y] << "\n";
q.push(mp(dist[new_x][new_y], mp(new_x, new_y)));
}
}
}
int M = dist[R2][C2];
if(M >= MOD){
cout << "Mission impossible!" << "\n";
}
else{
cout << "The shortest path is " << M << " steps long." << "\n";
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int T;
if(DEBUG){
T = 300;
}
else{
cin >> T;
}
for(int t = 1; t <= T; t++){
solve(t);
}
}