原题链接
#include<bits/stdc++.h> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ld pi = acos(-1.0); void solve() { //cout << sqrt(3)/3 << endl; //cout << pi << endl; ld a, rp; cin >> a >> rp; ld r1, r2; ld b = a/sqrt(2); r1 = sqrt(a * a + b * b)/2; r2 = r1 - sqrt(b * b - a * a/3); ld realr = sqrt(rp*rp - r2 * r2); //cout << r1 << " " << r2 << endl; if (rp < r2) { cout << 0 << endl;return; } ld cmp_r1 = sqrt(3)*a/6; ld cmp_r2 = sqrt(3)*a/3; ld s1 = sqrt(3)*a*a/4; //cout << realr << endl; //cout << cmp_r2 << endl; if (realr > cmp_r2) { cout << setprecision(10)<<4*s1 << endl; } else if (realr < cmp_r1) { //while (1); cout << setprecision(10)<< 4 * pi * realr*realr << endl; } else { ld r = realr; ld h = cmp_r1; ld Cos_1 = (4 * h * h-2 * r * r)/(2 * r*r); ld du = acos(Cos_1) * 3; ld s_san = h * sqrt(r * r - h * h); ld ans = s_san * 3 * 4; ans += pi * r * r * (2 * pi-du)/(2 * pi) * 4; cout << setprecision(10) << ans << endl; } } signed main() { ll t = 1;//cin >> t; while (t--) { solve(); } }