Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <istream>
- #include <ostream>
- #include <cmath>
- #include <vector>
- using namespace std;
- struct Point {
- double x = 0, y = 0;
- Point() {
- x = 0;
- y = 0;
- }
- Point(double a, double b) {
- x = a;
- y = b;
- }
- };
- struct Vector {
- double x, y;
- Vector(Point A, Point B) {
- x = B.x - A.x;
- y = B.y - A.y;
- }
- };
- long double operator ^ (Vector v1, Vector v2) {
- return v1.x * v2.y - v1.y * v2.x;
- }
- 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;
- }
- long double square(int n, vector<Point> points) {
- long double s = 0;
- for (int i = 1; i < n - 1; i++) {
- s += Vector(points[i], points[0]) ^ Vector(points[0], points[i + 1]);
- }
- s /= 2;
- return abs(s);
- }
- int main() {
- int n;
- Point a;
- cin >> n >> a;
- vector <Point> points(n + 1);
- for (int i = 0; i < n; i++) {
- cin >> points[i];
- }
- long double s1 = square(n, points);
- for (int i = n; i >= 1; i--){
- points[i] = points[i - 1];
- }
- points[0] = a;
- long double s2 = square(n + 1, points);
- cout << s1 << ' ' << s2 << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement