Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using double_type = double;
- #define double double_type
- #define long int64_t
- using namespace std;
- const double PI = atan2((double)0, (double)-1);
- const double eps = 1e-12;
- const double inf = 1e+12;
- bool double_equal(double a, double b) {
- return abs(a - b) <= eps;
- }
- bool double_less(double a, double b) {
- return a < b - eps;
- }
- bool double_greater(double a, double b) {
- return a > b + eps;
- }
- struct point {
- double x, y;
- point(double a, double b) :
- x(a),
- y(b) {}
- point() :
- point(0, 0) {}
- point to(point v) {
- return {v.x - x, v.y - y};
- }
- point operator+(point v) {
- return {v.x + x, v.y - y};
- }
- point operator-(point v) {
- return {x - v.x, y - v.y};
- }
- double operator*(point v) {
- return x * v.x + y * v.y;
- }
- double operator%(point v) {
- return x * v.y - y * v.x;
- }
- double angle() {
- return atan2(y, x);
- }
- friend double angle(point a, point b) {
- return atan2(a % b, a * b);
- }
- double len2() {
- return x * x + y * y;
- }
- double len() {
- return sqrt(len2());
- }
- double dist2(point p) {
- return to(p).len2();
- }
- double dist(point p) {
- return sqrt(dist2(p));
- }
- bool small(point a, point b) {
- return !double_less(to(a) * to(b), 0);
- }
- bool operator==(point p) {
- return double_equal(x, p.x) && double_equal(y, p.y);
- }
- bool operator!=(point p) {
- return !(operator==(p));
- }
- friend istream &operator>>(istream &in, point &p) {
- return in >> p.x >> p.y;
- }
- friend ostream &operator<<(ostream &out, point p) {
- return out << p.x << " " << p.y;
- }
- };
- struct line {
- point f, s;
- line(point a, point b) :
- f(a),
- s(b) {
- assert(a != b);
- }
- line() :
- f(),
- s() {}
- double dist2(point p) {
- double sq = p.to(f) % p.to(s);
- return sq * sq / f.dist2(s);
- }
- double dist(point p) {
- return p.to(f) % p.to(s) / f.dist(s);
- }
- bool have(point p) {
- return double_equal(f.to(p) % f.to(s), 0);
- }
- };
- struct segment {
- point f, s;
- segment(point a, point b) :
- f(a),
- s(b) {}
- segment() :
- f(),
- s() {}
- double dist2(point p) {
- if (f == s) {
- return f.dist2(p);
- }
- if (f.small(p, s) && s.small(p, f)) {
- return line(f, s).dist2(p);
- } else {
- return min(p.dist2(f), p.dist2(s));
- }
- }
- double dist(point p) {
- return sqrt(dist2(p));
- }
- bool have(point p) {
- return line(f, s).have(p) && !double_greater(p.to(f) * p.to(s), 0);
- }
- bool check_intersect(segment o) {
- if (have(o.f) || have(o.s) || o.have(f) || o.have(s)) {
- return true;
- }
- point a = f;
- point b = s;
- point c = o.f;
- point d = o.s;
- return double_less((a.to(b) % a.to(c)) * (a.to(b) % a.to(d)), 0) &&
- double_less((c.to(d) % c.to(a)) * (c.to(d) % c.to(b)), 0);
- }
- double dist2(segment o) {
- if (check_intersect(o)) {
- return 0;
- }
- double a = dist2(o.f);
- double b = dist2(o.s);
- double c = o.dist2(f);
- double d = o.dist2(s);
- return min({a, b, c, d});
- }
- double dist(segment o) {
- return sqrt(dist2(o));
- }
- };
- int main() {
- #ifdef LC
- assert(freopen("input.txt", "r", stdin));
- #else
- assert(freopen("goat1.in", "r", stdin));
- assert(freopen("goat1.out", "w", stdout));
- #endif
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout << fixed << setprecision(15);
- cerr << fixed << setprecision(15);
- double d, r;
- cin >> d >> r;
- d /=- 2;
- if (r <= d) {
- cout << PI * r * r << "\n";
- return 0;
- }
- double cosa2 = d / r;
- double sina2 = sqrt(1 - cosa2 * cosa2);
- double a = asin(sina2) * 2;
- cout << PI * r * r - 2 * r * r * (a - sin(a)) << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement