結果

問題 No.760 Where am I moved to?
ユーザー Pachicobue
提出日時 2018-12-08 02:18:25
言語 C++17(1z)
(gcc 8.2.0)
結果
AC  
実行時間 4 ms
コード長 2,596 Byte
コンパイル時間 2,836 ms
使用メモリ 8,916 KB
最終ジャッジ日時 2018-12-08 02:18:33

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
1a AC 2 ms
6,872 KB
1b AC 2 ms
6,868 KB
1c AC 1 ms
8,916 KB
2a AC 2 ms
6,872 KB
2b AC 1 ms
6,872 KB
2c AC 4 ms
6,872 KB
2d AC 1 ms
6,872 KB
2e AC 2 ms
6,868 KB
99_system_test1.txt AC 2 ms
6,868 KB
99_system_test2.txt AC 1 ms
6,872 KB
99_system_test3.txt AC 2 ms
6,868 KB
テストケース一括ダウンロード

ソースコード

diff #
#include <bits/stdc++.h>
using ld = long double;
constexpr ld PI = 3.141592653589793238462643383279;
constexpr ld EPS = 1e-10;
using A3 = std::array<ld, 3>;
using M3 = std::array<A3, 3>;
inline ld dot(const A3& a, const A3& b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; }
inline A3 mul(const M3& m, const A3& a) { return A3{dot(m[0], a), dot(m[1], a), dot(m[2], a)}; }
using A2 = std::array<ld, 2>;
using M2 = std::array<A2, 2>;
inline A2 add(const A2& a, const A2& b) { return A2{a[0] + b[0], a[1] + b[1]}; }
inline A2 sub(const A2& a, const A2& b) { return A2{a[0] - b[0], a[1] - b[1]}; }
inline M2 sub(const M2& m1, const M2& m2) { return M2{sub(m1[0], m2[0]), sub(m1[1], m2[1])}; }
inline ld dot(const A2& a, const A2& b) { return a[0] * b[0] + a[1] * b[1]; }
inline A2 mul(const M2& m, const A2& a) { return A2{dot(m[0], a), dot(m[1], a)}; }
inline M2 inv(const M2& m)
{
    const ld det = m[0][0] * m[1][1] - m[0][1] * m[1][0];
    return M2{{{m[1][1] / det, m[0][1] / (-det)}, {m[1][0] / (-det), m[0][0] / det}}};
}
inline M2 mul(const M2& m1, const M2 m2) { return M2{{{m1[0][0] * m2[0][0] + m1[0][1] * m2[1][0], m1[0][0] * m2[0][1] + m1[0][1] * m2[1][1]}, {m1[1][0] * m2[0][0] + m1[1][1] * m2[1][0], m1[1][0] * m2[0][1] + m1[1][1] * m2[1][1]}}}; }
constexpr M2 U2{{{1, 0}, {0, 1}}};
constexpr M2 Z2{{{0, 0}, {0, 0}}};
int main()
{
    ld xa, ya, ta, x11, y11, x12, y12, u21, v21, u22, v22;
    std::cin >> xa >> ya >> ta >> x11 >> y11 >> x12 >> y12 >> u21 >> v21 >> u22 >> v22, (ta *= PI) /= 180;
    const M3 w2s{{{std::cos(ta), std::sin(ta), -xa * std::cos(ta) - ya * std::sin(ta)}, {-std::sin(ta), std::cos(ta), xa * std::sin(ta) - ya * std::cos(ta)}, {0, 0, 1}}};
    const auto p1 = mul(w2s, A3{u21, v21, 1}), p2 = mul(w2s, A3{u22, v22, 1});
    const ld x21 = p1[0], y21 = p1[1], x22 = p2[0], y22 = p2[1];
    const M2 m1 = {{{x21, -y21}, {y21, x21}}}, m2 = {{{x22, -y22}, {y22, x22}}};
    const M2 m1m2 = inv(sub(m1, m2));
    const M2 m11 = m1m2, m12 = sub(Z2, m1m2), m21 = mul(sub(Z2, m1m2), m2), m22 = mul(m1m2, m1);
    const A2 q1 = A2{x11, y11}, q2 = A2{x12, y12};
    const A2 s1 = add(mul(m11, q1), mul(m12, q2)), s2 = add(mul(m21, q1), mul(m22, q2));
    std::cerr << s1[0] << " " << s1[1] << " " << s2[0] << " " << s2[1] << std::endl;
    const ld norm = std::sqrt(s1[0] * s1[0] + s1[1] * s1[1]);
    ld theta = (std::abs(1 - norm) > EPS ? 0 : s1[1] / norm >= EPS ? std::acos(s1[0] / norm) : 2 * PI - std::acos(s1[0] / norm));
    std::cout << std::fixed << std::setprecision(15) << s2[0] << " " << s2[1] << " " << theta / PI * 180 << std::endl;
    return 0;
}
0