#include #include #include #include #include using namespace std; const double pi = acos(-1); mt19937 mt(123456); int t; double p, w, v, gx, gy; bool solve2() { double gr = hypot(gx, gy); double mn = 1e100; double x = v+1; double y = w; double det = (1+v)*(1+v) + w*w; double gx = ::gx; double gy = ::gy; for (int i = 0; i < t - 1; i++) { double gx0 = gx; double gy0 = gy; gx = gx0*(v+1) + gy0*w; gy = gy0*(v+1) - gx0*w; gx /= det; gy /= det; double dist = hypot(gx, gy); double score = dist*dist + x*x + y*y; if (score < p - 0.00001) { cerr << "ok" << endl; printf("%.16f %.16f\n", -x, -y); for (int j = 0; j < t - 3 - i; j++) { printf("%.16f %.16f\n", 0.0, 0.0); } printf("%.16f %.16f\n", gx, gy); printf("%.16f %.16f\n", 0.0, 0.0); return true; } } cerr << "ng" << endl; return false; } bool solve() { double gr = hypot(gx, gy); double mn = 1e100; for (int ii = 0; ii < 5000; ii++) { double x = 1; double y = 0; vector vx(t); vector vy(t); double det = hypot(1 + v, w); double theta = uniform_real_distribution(0, 2*pi)(mt); double c = uniform_real_distribution(1e-6, 10)(mt); vx[0] = cos(theta) - 1; vy[0] = sin(theta); for (int i = 0; i < t; i++) { double x0 = x; double y0 = y; x = x0 - y0*w + x0*v + vx[i]; y = y0 + x0*w + y0*v + vy[i]; double r = hypot(x, y); double tr; tr = gr*pow((double)i / t, c); double d = tr - r; vx[i] += d*x / r; vy[i] += d*y / r; x += d*x / r; y += d*y / r; } vx[t - 1] += gx - x; vy[t - 1] += gy - y; double s = 0; for (int i = 0; i < t; i++) { s += vx[i]*vx[i] + vy[i]*vy[i]; } mn = min(mn, s); if (s < p - 0.001) { for (int i = 0; i < t; i++) { printf("%.16f %.16f\n", vx[i], vy[i]); } fprintf(stderr, "Sum: %.16f\n", s); fprintf(stderr, "p: %.16f\n", p); return true; } } cout << "FAIL" << endl; cout << endl; cout << mn << endl; return false; } int main() { int T; cin >> T; while (T--) { cin >> t >> p >> w >> v >> gx >> gy; if (!solve2()) { solve(); } } }