Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <bits/stdc++.h>
- using namespace std;
- #define all(x) x.begin(), x.end()
- #define endl '\n'
- #define sz(x) (int)(x).size()
- #define mp(x, y) make_pair(x, y)
- #define pb push_back
- #define pii pair<int, int>
- #define rep(i, f, t) for (auto i = (f); i < (t); ++i)
- #define ll long long
- #define double long double
- #define ull unsigned long long
- const int inf = (int)(2e9);
- const ll INF = (ll)(1e18);
- const int MOD = (int)(1e9 + 7);
- const double eps = (double)(1e-9);
- const double pi = acos(-1);
- const int maxn = (int)(1e5 + 10);
- const int maxm = (int)(2e5 + 10);
- void solve();
- template <typename A> inline void print(A x) { cout << x << endl; }
- template <typename A, typename B> inline void print(A x, B y) { cout << x << ' ' << y << endl; }
- template <typename A, typename B, typename C> inline void print(A x, B y, C z) { cout << x << ' ' << y << ' ' << z << endl; }
- template <typename A> inline void in(A &x) { cin >> x; }
- template <typename A, typename B> inline void in(A &x, B &y) { cin >> x >> y; }
- template <typename A, typename B, typename C> inline void in(A &x, B &y, C &z) { cin >> x >> y >> z; }
- template <typename A, typename B, typename C, typename D> inline void in(A &x, B &y, C &z, D &p) { cin >> x >> y >> z >> p; }
- template <typename A> inline void read(A begin, A end) { while (begin != end) cin >> *(begin++); }
- template <typename A> inline void write(A begin, A end) { while (begin != end) { cout << *(begin++) << ' '; } cout << endl; }
- ll power(ll a, ll b)
- {
- if (b == 0) return 1;
- if (b & 1) return power(a, b - 1) * a;
- ll tmp = power(a, b / 2);
- return tmp * tmp;
- }
- void use_files(string s) {
- freopen(string(s + ".in").c_str(), "r", stdin);
- freopen(string(s + ".out").c_str(), "w", stdout);
- }
- signed main()
- {
- std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- srand(time(0));
- cout << fixed << setprecision(20);
- solve();
- return 0;
- }
- struct Point {
- double x;
- double y;
- Point() {}
- Point(const double& _x, const double& _y) {
- x = _x;
- y = _y;
- }
- };
- bool operator==(const Point& a, const Point& b) {
- return a.x == b.x && a.y == b.y;
- }
- double polar_angle(const Point& p) {
- double alpha = atan2(p.y, p.x);
- if (alpha < 0) alpha += 2 * pi;
- return alpha;
- }
- istream& operator>>(istream& in, Point& p)
- {
- in >> p.x >> p.y;
- return in;
- }
- ostream& operator<<(ostream& out, Point& p) {
- out << p.x << ' ' << p.y;
- return out;
- }
- struct Vector{
- double x;
- double y;
- Vector() {}
- Vector(const double& _x, const double& _y) {
- x = _x;
- y = _y;
- }
- Vector(const Point& a, const Point& b) {
- x = b.x - a.x;
- y = b.y - a.y;
- }
- };
- double len(const Vector& a) {
- return sqrt(a.x * a.x + a.y * a.y);
- }
- double scalar_product(const Vector& a, const Vector& b)
- {
- return a.x * b.x + a.y * b.y;
- }
- double cross_product(const Vector& a, const Vector& b)
- {
- return a.x * b.y - b.x * a.y;
- }
- double alpha(const Vector& a, const Vector& b) {
- return acos(scalar_product(a, b) / (len(a) * len(b)));
- }
- Vector norm(const Vector& a) {
- Vector res;
- double l = len(a);
- res.x = a.x / l;
- res.y = a.y / l;
- return res;
- }
- struct Line {
- double a;
- double b;
- double c;
- Line() {}
- Line(const double& _A, const double& _B, const double& _C) {
- a = _A;
- b = _B;
- c = _C;
- }
- Line(const Point& first_point, const Point& second_point) {
- a = second_point.y - first_point.y;
- b = first_point.x - second_point.x;
- c = second_point.x * first_point.y - first_point.x * second_point.y;
- }
- };
- istream& operator>>(istream& in, Line& line) {
- in >> line.a >> line.b >> line.c;
- return in;
- }
- bool point_in_line(const Point& p, const Line& line) {
- return abs(line.a * p.x + line.b * p.y + line.c) < eps;
- }
- double dist_to_line_unsigned(const Point& p, const Line& line) {
- return abs(line.a * p.x + line.b * p.y + line.c) / sqrt(line.a * line.a + line.b * line.b);
- }
- double dist_to_line_signed(const Point& p, const Line& line) {
- return (line.a * p.x + line.b * p.y + line.c) / sqrt(line.a * line.a + line.b * line.b);
- }
- Point lines_intersection(const Line& first_line, const Line& second_line) {
- Point result;
- double matrix_determinant = (first_line.a * second_line.b - second_line.a * first_line.b);
- result.x = (first_line.b * second_line.c - second_line.b * first_line.c) / matrix_determinant;
- result.y = (first_line.c * second_line.a - second_line.c * first_line.a) / matrix_determinant;
- return result;
- }
- struct Segment {
- Point a;
- Point b;
- Segment() {}
- Segment(const Point& _a, const Point& _b) {
- a = _a;
- b = _b;
- }
- };
- istream& operator>>(istream& in, Segment& s) {
- in >> s.a >> s.b;
- return in;
- }
- double dist_to_segment(const Point& p, const Segment& seg) {
- Vector ab(seg.a, seg.b), ac(seg.a, p), bc(seg.b, p), ba(seg.b, seg.a);
- double result = min(len(ac), len(bc));
- Line line(seg.a, seg.b);
- if ((pi / 2.0) - alpha(ab, ac) > eps && (pi / 2.0) - alpha(bc, ba) > eps)
- result = min(result, dist_to_line_unsigned(p, line));
- return result;
- }
- bool point_in_segment(const Point& p, const Segment& seg) {
- double length = len(Vector(seg.a, seg.b));
- double len1 = len(Vector(seg.a, p)), len2 = len(Vector(seg.b, p));
- return (abs(length - (len1 + len2)) < eps);
- }
- struct Polygon {
- vector<Point> poly;
- Polygon(const int& _size) {
- poly.resize(_size);
- for (int i = 0; i < _size; ++i)
- cin >> poly[i];
- }
- };
- int sign(double x)
- {
- if (abs(x) < eps) return 0;
- else if (x < 0) return -1;
- else return 1;
- }
- Point get_polygon_point(const Polygon& p, const int& index)
- {
- return p.poly[index % p.poly.size()];
- }
- Vector get_polygon_edge(const Polygon& p, const int& index) {
- Vector result(get_polygon_point(p, index), get_polygon_point(p, index + 1));
- return result;
- }
- bool polygon_is_convex(const Polygon& p)
- {
- bool result = true;
- int _sign = 0, i = 0;
- while (i++ < p.poly.size() && _sign == 0)
- _sign = sign(cross_product(get_polygon_edge(p, i), get_polygon_edge(p, i + 1)));
- for (i; i < p.poly.size(); ++i) {
- int t = sign(cross_product(get_polygon_edge(p, i), get_polygon_edge(p, i + 1)));
- result &= (t == _sign || t == 0);
- }
- return result;
- }
- double orient_angle(const Vector& a, const Vector& b) {
- return alpha(a, b) * sign(cross_product(a, b));
- }
- bool point_in_polygon(const Point& p, const Polygon& poly)
- {
- for (int i = 0; i < poly.poly.size(); ++i)
- if (point_in_segment(p, Segment(get_polygon_point(poly, i), get_polygon_point(poly, i + 1))))
- return true;
- double sum = 0;
- for (int i = 0; i < poly.poly.size(); ++i)
- sum += orient_angle(Vector(p, get_polygon_point(poly, i)), Vector(p, get_polygon_point(poly, i + 1)));
- return (abs(abs(sum) - 2 * pi) < eps);
- }
- double square_polygon(const Polygon& p)
- {
- double result = 0;
- for (int i = 0; i < p.poly.size(); ++i)
- result += (cross_product(Vector(get_polygon_point(p, i + 1), get_polygon_point(p, i)), Vector(get_polygon_point(p, i + 1), get_polygon_point(p, i + 2))) / 2);
- return result;
- }
- void solve()
- {
- int n;
- cin >> n;
- Polygon poly(n);
- print(square_polygon(poly));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement