D - Opposite Editorial by TumoiYorozu


C++ で複素数クラス(complex) を用いた回答例です。
入力の2つの点を a, b として、その中点を m とします。
a - m で m から a へ伸びるベクトルが得られ、それを \(2\pi/n\) だけ回転したベクトルを m に足すと、目的の解が得られます。
長さ r, 角度 t の複素数は polar(r, t) を用いて得ることができます。

int main() {
    int n;
    double x, y;
    complex<double> a, b;
    
    cin >> n;
    cin >> x >> y; a = { x, y };
    cin >> x >> y; b = { x, y };

    auto m = (a + b) / 2.0;

    auto res = m + (a - m) * polar(1.0, M_PI*2.0/n);

    cout << setprecision(9) << res.real() << " " << res.imag() << endl;
}

posted:
last update: