Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <istream>
  3. #include <ostream>
  4. #include <cmath>
  5. #include <vector>
  6. using namespace std;
  7. struct Point {
  8.     double x = 0, y = 0;
  9.     Point() {
  10.         x = 0;
  11.         y = 0;
  12.     }
  13.     Point(double a, double b) {
  14.         x = a;
  15.         y = b;
  16.     }
  17. };
  18. struct Vector {
  19.     double x, y;
  20.  
  21.     Vector(Point A, Point B) {
  22.         x = B.x - A.x;
  23.         y = B.y - A.y;
  24.     }
  25. };
  26. long double operator ^ (Vector v1, Vector v2) {
  27.     return v1.x * v2.y - v1.y * v2.x;
  28. }
  29.  
  30. istream & operator>> (istream & in, Point & P) {
  31.     in >> P.x >> P.y;
  32.     return in;
  33. }
  34. ostream & operator<< (ostream & out, Point & P) {
  35.     out << P.x << " " << P.y;
  36.     return out;
  37. }
  38. long double square(int n, vector<Point> points) {
  39.     long double s = 0;
  40.     for (int i = 1; i < n - 1; i++) {
  41.         s += Vector(points[i], points[0]) ^ Vector(points[0], points[i + 1]);
  42.     }
  43.     s /= 2;
  44.     return abs(s);
  45. }
  46. int main() {
  47.     int n;
  48.     Point a;
  49.     cin >> n >> a;
  50.     vector <Point> points(n + 1);
  51.     for (int i = 0; i < n; i++) {
  52.         cin >> points[i];
  53.     }
  54.     long double s1 = square(n, points);
  55.     for (int i = n; i >= 1; i--){
  56.         points[i] = points[i - 1];
  57.  
  58.     }
  59.     points[0] = a;
  60.     long double s2 = square(n + 1, points);
  61.     cout << s1 << ' ' << s2 << '\n';
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement