#include #include #include #include #include using namespace std; struct State { long double v; vectort; }; bool operator<(const State &a1, const State &a2) { if (a1.v < a2.v) return true; return false; } int Rand() { return (1 << 20)*(rand() % 1024) + (1 << 10)*(rand() % 1024) + (rand() % 1024); } vectorconcatenate(vectorA1, vectorA2) { vectorI; for (int i = 0; i < A1.size(); i++) I.push_back(A1[i]); for (int i = 0; i < A2.size(); i++) I.push_back(A2[i]); return I; } vectorsolve(long double T) { vectorF; int G1 = T / 8; while (F.size() <= 1000) { int Y = Rand() % (G1*G1); long double I = (T / 8) - sqrtl(1.0L*Y); long double J = I*I; int K1 = J, K2 = K1 + 1; long double L1 = sqrtl(1.0L*Y) + sqrtl(1.0L*K1); if (abs(T / 8 - L1) <= 1.0e-4) { F.push_back(State{ L1, vector{Y, K1} }); } long double L2 = sqrtl(1.0L*Y) + sqrtl(1.0L*K2); if (abs(T / 8 - L2) <= 1.0e-4) { F.push_back(State{ L2, vector{Y, K2} }); } } sort(F.begin(), F.end()); long double EPS1 = T / 8, EPS = 1e-4; for (int i = 0; i < 3; i++) { vectorG; EPS1 *= 2.0L; EPS *= 0.01L; for (int j = 0; j < F.size(); j++) { long double R1 = (EPS1 - F[j].v); int pos1 = lower_bound(F.begin(), F.end(), State{ R1,vector{} }) - F.begin(); if (pos1 >= 1) { long double Y = F[pos1 - 1].v + F[j].v; if (abs(Y - EPS1) <= EPS) G.push_back(State{ Y,concatenate(F[pos1 - 1].t,F[j].t) }); } if (pos1 < F.size()) { long double Y = F[pos1].v + F[j].v; if (abs(Y - EPS1) <= EPS) G.push_back(State{ Y,concatenate(F[pos1].t,F[j].t) }); } } F = G; } if (F.size() == 0) return vector{}; return F[0].t; } int main() { srand((unsigned)time(NULL)); int Q; cin >> Q; for (int i = 1; i <= Q; i++) { long double P; cin >> P; vectorZ; while (true) { Z = solve(P); if (Z.size() >= 1) break; } long double E = 0; cout << Z.size(); for (int j = 0; j < Z.size(); j++) { cout << " " << Z[j]; E += sqrtl(1.0L*Z[j]); }cout << endl; //printf("score = %.13Lf\n", abs(P - E)); } return 0; }