AlexNeagu11

Arie Poligon 2

Mar 19th, 2022
53
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.  
  7. struct point {
  8. long double x, y;
  9. void read() {
  10. in >> x >> y;
  11. }
  12. void write() {
  13. out << x << ' ' << y << '\n';
  14. }
  15. point operator - (const point &B) const {
  16. return point{x - B.x, y - B.y};
  17. }
  18. void operator -= (const point &B) {
  19. x -= B.x;
  20. y -= B.y;
  21. }
  22. long double operator * (const point &B) const {
  23. return x * B.y - y * B.x;
  24. }
  25. long double orientation(const point &A, const point &B) const {
  26. return (A - *this) * (B - *this);
  27. }
  28. long double dist(point A) {
  29. A -= *this;
  30. return A.x * A.x + A.y * A.y;
  31. }
  32. bool operator <(const point &A) {
  33. if(x == A.x) {
  34. return y < A.y;
  35. }
  36. return x < A.x;
  37. }
  38.  
  39. };
  40.  
  41.  
  42. int32_t main() {
  43. int N;
  44. in >> N;
  45. vector<point> polygon(N);
  46. for(int i = 0; i < N; ++i) {
  47. polygon[i].read();
  48. }
  49. long double area = 0;
  50. for(int i = 0; i < N; ++i) {
  51. int j = (i + 1) % N;
  52. area += polygon[i] * polygon[j];
  53. }
  54. out << fixed << setprecision(10) << fabs(area) / 2.0 << '\n';
  55. }
Advertisement
Add Comment
Please, Sign In to add comment