結果
問題 |
No.764 浮動点
|
ユーザー |
|
提出日時 | 2019-05-09 23:58:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,500 ms |
コード長 | 1,803 bytes |
コンパイル時間 | 1,637 ms |
コンパイル使用メモリ | 171,884 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-02 00:53:26 |
合計ジャッジ時間 | 2,702 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#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; }