結果

問題 No.3344 Common Tangent Line
コンテスト
ユーザー 2251799813685248
提出日時 2025-10-29 14:47:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 428 ms / 3,000 ms
コード長 2,024 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 117,128 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-13 21:03:14
合計ジャッジ時間 20,787 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>


using namespace std;
#define ll long long
#define ld long double

void solve(){
    ll a,b,r1;
    ll c,d,r2;
    cin >> a >> b >> r1 >> c >> d >> r2;

    ld A = a, B = b, C = c, D = d, R1 = r1, R2 = r2;//各数字のlong double版を作成
    
    ll L_squared = (c-a)*(c-a)+(d-b)*(d-b);//円の中心間距離の二乗

    vector<ld> theta(4);
    if (d - b == 0){
        theta[0] = acosl((R1+R2)/(C-A));
        theta[1] = -theta[0];
        theta[2] = acosl((R2-R1)/(A-C));
        theta[3] = -theta[2];
    }
    if (d - b > 0){
        theta[0] = asinl((R1+R2)/sqrtl(L_squared)) - atanl((C-A)/(D-B));
        theta[1] = M_PIl - asinl((R1+R2)/sqrtl(L_squared)) - atanl((C-A)/(D-B));
        theta[2] = M_PIl + asinl((R2-R1)/sqrtl(L_squared)) - atanl((C-A)/(D-B));
        theta[3] = 2*M_PIl - asinl((R2-R1)/sqrtl(L_squared)) - atanl((C-A)/(D-B));
    }
    if (d - b < 0){
        theta[0] = M_PIl + asinl((R1+R2)/sqrtl(L_squared)) - atanl((C-A)/(D-B));
        theta[1] = 2*M_PIl - asinl((R1+R2)/sqrtl(L_squared)) - atanl((C-A)/(D-B));
        theta[2] = asinl((R2-R1)/sqrtl(L_squared)) - atanl((C-A)/(D-B));
        theta[3] = M_PIl - asinl((R2-R1)/sqrtl(L_squared)) - atanl((C-A)/(D-B));
    }

    ld X = 0.0;
    for (ll i = 0; i < 4; i++){//それぞれのθの値に対して、直線の式の係数を求め、変換を行ってXに加算する。

        ld s = cosl(theta[i]);
        ld t = sinl(theta[i]);
        ld u = -R1 - B*sinl(theta[i]) - A*cosl(theta[i]);

        ld M = max(abs(s),max(abs(t),abs(u)));
        X += abs(s/M + t/M + u/M);
    }
    cout << X << "\n";
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll T;
    cin >> T;
    cout << fixed << setprecision(16);
    for (ll i = 0; i < T; i++){
        solve();
    }
}
0