|
|
вернуться в форумaccepted //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; int main() { cout.precision(10); double r, a; cin >> a >> r; double h = 2 * sqrt(r * r - a * a / 4); if (r <= a / 2) cout << pi * r * r / 2 << endl; else if (r >= a * sqrt(2) / 2) cout << a * a << endl; else cout << pi * r * r + a * h - 2 * r * r * (double)asin(a * h / (2 * r * r)) << endl; re 0; } Re: accepted Look at this overkill and still Accepted #include <math.h> #include <iostream> #include <math.h> #include <iomanip> using namespace std; double n, r; double pi = 3.141592654; int main() { cin >> n >> r; if(r <= n / 2) { cout << fixed << setprecision(3) << pi * r * r; return 0; } if(r >= n * sqrt(2) / 2) { cout << fixed << setprecision(3) << n * n; return 0; } cout << fixed << setprecision(3) << (r * (r * asin(-sqrt(r * r - n * n / 4) / r) + (-sqrt(r * r - n * n / 4) * -sqrt(-(-sqrt(r * r - n * n / 4) - r) * (-sqrt(r * r - n * n / 4) + r))) / r) / 2 - r * (r * asin(-n / 2 / r) + (-n / 2 * -sqrt(-(-n / 2 - r) * (-n / 2 + r))) / r) / 2 + n / 2 * sqrt(r * r - n * n / 4)) * 4; return 0; } |
|
|