Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3.  
  4. typedef struct Point
  5. {
  6. double x;
  7. double y;
  8. } point;
  9.  
  10. double S_count(point a, point b, point c);
  11. double S_count1(point a, point b, point c);
  12.  
  13. int main(void)
  14. {
  15. int n;
  16. scanf("%d", &n);
  17. point arr[n];
  18. for (int i = 0; i < n; i++)
  19. scanf("%lf %lf", &arr[i].x, &arr[i].y);
  20.  
  21. double S = 0;
  22. for (int i = 1; i < n - 1; i++)
  23. {
  24. S += S_count(arr[0], arr[i], arr[i + 1]);
  25.  
  26. }
  27.  
  28. double S1 = 0;
  29. for (int i = 1; i < n - 1; i++)
  30. {
  31. S1 += S_count1(arr[0], arr[i], arr[i + 1]);
  32. }
  33.  
  34. printf("%lf %lf", S, S1);
  35. return 0;
  36. }
  37.  
  38. double S_count(point a, point b, point c)
  39. {
  40. double ab = sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
  41. double bc = sqrt((c.x - b.x) * (c.x - b.x) + (c.y - b.y) * (c.y - b.y));
  42. double ac = sqrt((c.x - a.x) * (c.x - a.x) + (c.y - a.y) * (c.y - a.y));
  43. double p = (ab + bc + ac) / 2;
  44.  
  45. return sqrt(p * (p - ab) * (p - bc) * (p - ac));
  46. }
  47.  
  48. double S_count1(point a, point b, point c)
  49. {
  50. return fabs(((a.x * b.y + a.y * c.x + b.x * c.y) - (a.y * b.x + a.x * c.y + b.y * c.x)) / 2.0);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement