#include #include using namespace std; #define rep(i,n) for(long long i = 0; i < (long long)(n); i++) #define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++) #define pb push_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define mt make_tuple #define mp make_pair #define ZERO(a) memset(a,0,sizeof(a)) template bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } #define exists find_if #define forall all_of using ll = long long; using vll = vector; using vvll = vector; using P = pair; using vi = vector; using vvi = vector; vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; } inline void input(int &v){ v=0;char c=0;int p=1; while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p; } template ostream &operator<<(ostream &o, const pair &v) { o << "(" << v.first << ", " << v.second << ")"; return o; } template struct seq{}; template struct gen_seq : gen_seq{}; template struct gen_seq<0, Is...> : seq{}; template void print_tuple(basic_ostream& os, Tuple const& t, seq){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get(t)), 0)...}; } template auto operator<<(basic_ostream& os, tuple const& t) -> basic_ostream& { os << "("; print_tuple(os, t, gen_seq()); return os << ")"; } ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; o << endl; } return o; } template ostream &operator<<(ostream &o, const vector &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]"; return o; } template ostream &operator<<(ostream &o, const set &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template ostream &operator<<(ostream &o, const unordered_set &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template ostream &operator<<(ostream &o, const map &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template ostream &operator<<(ostream &o, const unordered_map &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]"; return o; } vector range(const int x, const int y) { vector v(y - x + 1); iota(v.begin(), v.end(), x); return v; } template istream& operator>>(istream& i, vector& o) { rep(j, o.size()) i >> o[j]; return i;} string bits_to_string(ll input, ll n=64) { string s; rep(i, n) s += '0' + !!(input & (1ll << i)); reverse(all(s)); return s; } template ostream &operator<<(ostream &o, const priority_queue &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " ";} o << endl; return o; } template unordered_map counter(vector vec){unordered_map ret; for (auto&& x : vec) ret[x]++; return ret;}; string substr(string s, P x) {return s.substr(x.fi, x.se - x.fi); } void vizGraph(vvll& g, int mode = 0, string filename = "out.png") { ofstream ofs("./out.dot"); ofs << "digraph graph_name {" << endl; set

memo; rep(i, g.size()) rep(j, g[i].size()) { if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i)))) continue; memo.insert(P(i, g[i][j])); ofs << " " << i << " -> " << g[i][j] << (mode ? " [arrowhead = none]" : "")<< endl; } ofs << "}" << endl; ofs.close(); system(((string)"dot -T png out.dot >" + filename).c_str()); } size_t random_seed; namespace std { using argument_type = P; template<> struct hash { size_t operator()(argument_type const& x) const { size_t seed = random_seed; seed ^= hash{}(x.fi); seed ^= (hash{}(x.se) << 1); return seed; } }; }; // hash for various class namespace myhash{ const int Bsizes[]={3,9,13,17,21,25,29,33,37,41,45,49,53,57,61,65,69,73,77,81}; const int xor_nums[]={0x100007d1,0x5ff049c9,0x14560859,0x07087fef,0x3e277d49,0x4dba1f17,0x709c5988,0x05904258,0x1aa71872,0x238819b3,0x7b002bb7,0x1cf91302,0x0012290a,0x1083576b,0x76473e49,0x3d86295b,0x20536814,0x08634f4d,0x115405e8,0x0e6359f2}; const int hash_key=xor_nums[rand()%20]; const int mod_key=xor_nums[rand()%20]; template struct myhash{ std::size_t operator()(const T& val) const { return (hash{}(val)%mod_key)^hash_key; } }; }; template class uset:public std::unordered_set> { using SET=std::unordered_set>; public: uset():SET(){SET::rehash(myhash::Bsizes[rand()%20]);} }; uint32_t randxor() { static uint32_t x=1+(uint32_t)random_seed,y=362436069,z=521288629,w=88675123; uint32_t t; t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } struct timeval start; long double sec() { struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + (tv.tv_usec - start.tv_usec) * 1e-6; } struct init_{init_(){ gettimeofday(&start, NULL); ios::sync_with_stdio(false); cin.tie(0); struct timeval myTime; struct tm *time_st; gettimeofday(&myTime, NULL); time_st = localtime(&myTime.tv_sec); srand(myTime.tv_usec); random_seed = RAND_MAX / 2 + rand() / 2; }} init__; #define ldout fixed << setprecision(40) typedef long double number; const number eps = 1e-8; using vec = vector; using mat = vector; ostream &operator<<(ostream &o, const vec &v) { for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } cout << endl; return o; } ostream &operator<<(ostream &o, const mat &v) { for (int i = 0; i < v.size(); i++) { cout << v[i]; } return o; } // O( n^2 ) vec zero(int n) { return vec(n); } // O( n m ) mat zero(int n, int m) { mat A(n, vec(m, 0)); return A; } mat operator*(const mat& t1, const mat& t2) { assert(t1[0].size() == t2.size()); mat ret = zero(t1.size(), t2[0].size()); rep(i, t1.size()) { rep(j, t2[0].size()) { rep(k, t1[0].size()) { ret[i][j] += t1[i][k] * t2[k][j]; } } } return ret; } vec operator*(const mat& t1, const vec& t2) { assert(t1[0].size() == t2.size()); vec ret(t1.size()); rep(i, t1.size()) { rep(j, t2.size()) { ret[i] += t1[i][j] * t2[j]; } } return ret; } vec operator+(const vec& t1, const vec& t2) { assert(t1.size() == t2.size()); vec ret(t1.size()); rep(i, t1.size()) { ret[i] = t1[i] + t2[i]; } return ret; } mat operator+(const mat& t1, const mat& t2) { assert(t1.size() == t2.size() && t1[0].size() == t2[0].size()); mat ret = zero(t1.size(), t1[0].size()); rep(i, t1.size()) { rep(j, t1[0].size()) { ret[i][j] = t1[i][j] + t2[i][j]; } } return ret; } vec operator-(const vec& t1, const vec& t2) { assert(t1.size() == t2.size()); vec ret(t1.size()); rep(i, t1.size()) { ret[i] = t1[i] - t2[i]; } return ret; } mat operator-(const mat& t1, const mat& t2) { assert(t1.size() == t2.size() && t1[0].size() == t2[0].size()); mat ret = zero(t1.size(), t1[0].size()); rep(i, t1.size()) { rep(j, t1[0].size()) { ret[i][j] = t1[i][j] - t2[i][j]; } } return ret; } mat operator-(const mat& t1) { mat ret = t1; rep(i, ret.size()) { rep(j, ret[0].size()) { ret[i][j] *= -1; } } return ret; } mat inverse(const mat& t) { assert(t.size() == t[0].size()); assert(t.size() == 2); // TODO mat ret = zero(2, 2); ret[0][0] = t[1][1]; ret[0][1] = -t[1][0]; ret[1][0] = -t[0][1]; ret[1][1] = t[0][0]; rep(i, 2) rep(j, 2) { ret[i][j] /= (t[0][0] * t[1][1] - t[0][1] * t[1][0]); } return ret; } mat transpose(const mat& t) { mat ret = zero(t[0].size(), t.size()); rep(i, t.size()) rep(j, t[0].size()) { ret[j][i] = t[i][j]; } return ret; } mat block(const mat& t, ll si, ll sj, ll i0, ll j0) { assert(i0+si<=t.size() && j0+sj <= t[0].size()); mat ret = zero(si, sj); rep(i, si) rep(j, sj) { ret[i][j] = t[i0+i][j0+j]; } return ret; } number omega = 0.5; number vv = -0.5; vec f(vec x, vec u) { mat F_x = zero(2, 2); F_x[0][0] = vv+(number)1, F_x[0][1] = -omega; F_x[1][0] = omega, F_x[1][1] = vv+(number)1; return F_x * x + u; } // Sx(S+U) mat getF(void) { mat F = zero(2, 4); F[0][0] = vv+(number)1; F[0][1] = -omega; F[0][2] = (number)1; F[0][3] = 0; F[1][0] = omega; F[1][1] = vv+(number)1; F[1][2] = 0; F[1][3] = 1; return F; } // Sx1 vec getf(void) { return zero(2); } pair evaluate(number g_x, number g_y, number output_coeff, ll T) { // X=U=2 vector C(T+1, zero(4, 4)); vector c(T+1, zero(4)); C[T][0][0] = 1, C[T][1][1] = 1; c[T][0] = -g_x, c[T][1] = -g_y; rep(t, T+1) C[t][2][2] = output_coeff, C[t][3][3] = output_coeff; vector Q(T+1, zero(4, 4)); // (S+U)x(S+U) vector q(T+1, zero(4)); // (S+U)x1 vector V(T+2, zero(2, 2)); // SxS vector v(T+2, zero(2)); // Sx1 vector K(T+2, zero(2, 2)); // UxS vector k(T+2, zero(2)); // Ux1 // cout <<"HOGE"<= 0; t--) { // cout < x(T+2, zero(2)); vector x_brutal(T+2); vector y_brutal(T+2); vector u(T+2, zero(2)); x[0][0] = 1, x[0][1] = 0; x_brutal[0] = 1; rep(t, T) { vec u_tmp = K[t] * x[t] + k[t]; u[t] = u_tmp; x[t+1] = f(x[t], u[t]); number ux = u[t][0]; number uy = u[t][1]; x_brutal[t+1] = x_brutal[t] - y_brutal[t] * omega + x_brutal[t] * vv + ux; y_brutal[t+1] = y_brutal[t] + x_brutal[t] * omega + y_brutal[t] * vv + uy; } /* rep(i, T+1) cout << " " << x[i][0] << " " << x[i][1] << endl; */ rep(i, T) cout << ldout << u[i][0] << " " << u[i][1] << endl; number usum = 0; rep(i, T) usum += u[i][0] * u[i][0] + u[i][1] * u[i][1]; return mp(usum, sqrt(pow(x_brutal[T] - g_x, 2) + pow(y_brutal[T] - g_y, 2))); } ll randr(ll i, ll j) { if (i > j) return i; else return (ll)rand() % (j - i + 1) + i; } number randrf(number i, number j) { number ret = ((number)rand() / (number)RAND_MAX) * ((number)j - (number)i) + (number)i; return ret; } int main(int argc, char** argv) { cout << ldout; number g_x, g_y, output_coeff = 1e-9; number k; ll T; #if 0 /* { T = 1; k = 1e9; omega = randrf(-10, 10); vv = randrf(-10, 10); g_x = randrf(-100, 100); g_y = randrf(-100, 100); auto err = evaluate(g_x, g_y, output_coeff, T); assert(err.se <= 1e-4); assert(err.fi <= k); cout << ldout << T << " " << err.fi * 1.01 << endl; cout << omega << " " << vv << endl; cout << g_x << " " << g_y << endl; } */ { ll q = 1000; cout << q << endl; rep(_, q) { T = 15; k = 1e9; omega = randrf(-10, 10); vv = randrf(-10, 10); g_x = randrf(-100, 100); g_y = randrf(-100, 100); auto err = evaluate(g_x, g_y, output_coeff, T); assert(err.se <= 1e-4); assert(err.fi <= k); cout << ldout << T << " " << 1e9 << " " << omega << " " << vv << " " << g_x << " " << g_y << endl; } } /* rep(_, 100000) { T = randr(15, 15); k = _ * 1; omega = 1; vv = -1; g_x = 91; g_y = -48; auto err = evaluate(g_x, g_y, output_coeff, T); if (err.se && err.fi <= k) { cout << ldout << T << " " << err.fi * 1.01 << endl; cout << omega << " " << vv << endl; cout << g_x << " " << g_y << endl; exit(0); } } */ #else ll q; cin >> q; rep(_, q) { cin >> T >> k >> omega >> vv >> g_x>> g_y; assert(1<=T&&T<=15); assert(0<=k&&k<=1e9); assert(-10<=omega&&omega<=10); assert(-10<=vv&&vv<=10); assert(-100<=g_x&&g_x<=100); assert(-100<=g_y&&g_y<=100); auto err = evaluate(g_x, g_y, output_coeff, T); // cerr << err << endl; // cout << err.fi << " " << err.se << " " << T << " " << k << " " << vv << " " << g_x << " " << g_y << endl; assert(err.se <= 1e-4); } #endif return 0; }