結果

問題 No.620 ぐるぐるぐるりん
ユーザー PachicobuePachicobue
提出日時 2017-12-20 20:59:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 1,000 ms
コード長 3,512 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 203,180 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 21:27:29
合計ジャッジ時間 4,428 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 50 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 48 ms
4,380 KB
testcase_29 AC 49 ms
4,380 KB
testcase_30 AC 50 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << fixed << setprecision(30) << x << endl

using namespace std;
using ll = long long;
using ld = long double;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ld PI = static_cast<ld>(3.1415926535897932384626433832795);
constexpr ld EPS = static_cast<ld>(1e-8);

struct Vec {
    Vec() : dx{0}, dy{0} {}
    Vec(const ld dx, const ld dy) : dx{dx}, dy{dy} {}
    ld dx;
    ld dy;
    Vec rotate(const ld theta) const
    {
        Vec ans;
        ans.dx = cosl(theta) * dx - sinl(theta) * dy;
        ans.dy = sinl(theta) * dx + cosl(theta) * dy;
        return ans;
    }
    Vec operator*(const ld x) const
    {
        Vec ans = *this;
        ans.dx *= x;
        ans.dy *= x;
        return ans;
    }
    ld norm() const
    {
        return hypotl(dx, dy);
    }
    void normalize()
    {
        const ld n = norm();
        dx /= n;
        dy /= n;
    }
};
ostream& operator<<(ostream& os, const Vec& v)
{
    os << "(" << v.dx << "," << v.dy << ")";
    return os;
}

int main()
{
    int N;
    cin >> N;
    for (int q = 0; q < N; q++) {
        int T;
        cin >> T;
        long double p, omega, v, gx, gy;
        cin >> p >> omega >> v >> gx >> gy;
        const ld l = hypotl(omega, (ld)(1 + v));
        const ld theta = arg(complex<ld>{(ld)(1 + v), omega});
        Vec g{gx - powl(l, T) * cosl((ld)T * theta), gy - powl(l, T) * sinl((ld)T * theta)};
        ld F = 0;
        for (int i = 0; i < T; i++) {
            if (l < 1) {
                F += powl(l, 2 * T - 2 - 2 * i);
            } else {
                F += powl(l, 2 * i);
            }
        }
        vector<Vec> u(T);
        ld sumation = 0;
        if (g.norm() < EPS) {
            for (int i = 0; i < T; i++) {
                cout << fixed << setprecision(50) << (long double)0 << " " << (long double)0 << endl;
            }
        } else {
            if (omega == 0 and v == -1) {
                for (int i = 0; i < T; i++) {
                    if (i == T - 1) {
                        u[i] = Vec{gx, gy};
                        sumation = u[i].norm() * u[i].norm();
                    } else {
                        u[i] = Vec{};
                    }
                    cout << fixed << setprecision(50) << (long double)u[i].dx << " " << (long double)u[i].dy << endl;
                }
            } else {
                for (int i = 0; i < T; i++) {
                    const Vec v = g.rotate(theta * (ld)(i + 1 - T)) * (powl(l, T - 1 - i) / F);
                    u[i] = v;
                    sumation += v.norm() * v.norm();
                    cout << fixed << setprecision(50) << (long double)v.dx << " " << (long double)v.dy << endl;
                }
            }
        }
        assert(sumation < p);
        ld X = 1;
        ld Y = 0;
        for (int i = 0; i < T; i++) {
            ld x = X * ((ld)1 + v) - Y * omega + u[i].dx;
            ld y = Y * ((ld)1 + v) + X * omega + u[i].dy;
            X = x;
            Y = y;
        }
        const ld err = hypot(X - gx, Y - gy);
        assert(err <= 0.0001);
        show(err);
    }
    return 0;
}
0