AlexNeagu11

Arie Poligon

Mar 19th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. ifstream in("aria.in");
  5. ofstream out("aria.out");
  6. struct point {
  7. long double x, y;
  8. void read() {
  9. in >> x >> y;
  10. }
  11. void write() {
  12. out << x << ' ' << y << '\n';
  13. }
  14. point operator - (const point &B) const {
  15. return point{x - B.x, y - B.y};
  16. }
  17. void operator -= (const point &B) {
  18. x -= B.x;
  19. y -= B.y;
  20. }
  21. double operator * (const point &B) const {
  22. return x * B.y - y * B.x;
  23. }
  24. long double orientation(const point &A, const point &B) const {
  25. return (A - *this) * (B - *this);
  26. }
  27. long double dist(point A) {
  28. A -= *this;
  29. return A.x * A.x + A.y * A.y;
  30. }
  31. bool operator <(const point &A) {
  32. if(x == A.x) {
  33. return y < A.y;
  34. }
  35. return x < A.x;
  36. }
  37.  
  38. };
  39.  
  40.  
  41. int32_t main() {
  42. int N;
  43. in >> N;
  44. vector<point> polygon(N);
  45. for(int i = 0; i < N; ++i) {
  46. polygon[i].read();
  47. }
  48. long double area = 0;
  49. for(int i = 2; i < N; ++i) {
  50. area += (polygon[i - 1] - polygon[0]) * (polygon[i] - polygon[0]);
  51. }
  52. out << fixed << setprecision(10) << fabsl(area) / 2.0 << '\n';
  53. }
Advertisement
Add Comment
Please, Sign In to add comment