結果

問題 No.764 浮動点
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-09 23:58:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 1,803 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 168,536 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 17:48:15
合計ジャッジ時間 3,340 ms
ジャッジサーバーID
(参考情報)
judge14 / 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,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <cmath>
using namespace std;

double PI = acos(0) * 2.0;

void fill_max_min(const vector<int> &Ls, int N, vector<int> &max0, vector<int> &min0){
    max0[0] = Ls[0];
    min0[0] = Ls[0];
    int largest = Ls[0];
    for (int i = 1; i <= N; ++i){
        largest = max(largest, Ls[i]);
        max0[i] = max0[i - 1] + Ls[i];
        min0[i] = max(2 * largest - max0[i], 0);
    }
}

double area(int C, int A, int B){
    if (C >= A + B) return 0.0;
    if (A >= C + B) return PI * B * B;
    if (B >= C + A) return PI * A * A;
    double a = A;
    double b = B;
    double c = C;
    double theta = acos((b * b + c * c - a * a)/(2 * b * c));
    double phi = acos((a * a + c * c - b * b)/(2 * a * c));
    return  b * b * (theta - sin(2 * theta)/2.0) + a * a * (phi - sin(2 * phi)/2.0);
}

double calc_area(int f, int a, int b, int c, int d){
    // x, y
    // a^2 < x^2 + y^2 < b^2
    // c^2 < (x-f)^2 + y^2 < d^2
    // B and D - (A and D) - (C and B) + (A and C)
    return area(f, b, d) - area(f, a, d) - area(f, b, c) + area(f, a, c);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, L0;
    cin >> N >> L0;
    vector<int> Ls(N + 1, 0);
    for (auto & L : Ls) cin >> L;
    vector<double> result(N, 0);
    vector<int> max0(N + 1, 0);
    vector<int> max1(N + 1, 0);
    vector<int> min0(N + 1, 0);
    vector<int> min1(N + 1, 0);
    fill_max_min(Ls, N, max0, min0);
    reverse(Ls.begin(), Ls.end());
    fill_max_min(Ls, N, max1, min1);
    reverse(max1.begin(), max1.end());
    reverse(min1.begin(), min1.end());
    for (int i = 1; i < N; ++i){
        result[i] = calc_area(L0, min0[i], max0[i], min1[i+1], max1[i+1]);
    }
    cout.precision(6);
    cout << fixed;
    for (auto a : result) cout << a << '\n';
    return 0;
}
0