Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- typedef struct Point
- {
- double x;
- double y;
- } point;
- double S_count(point a, point b, point c);
- double S_count1(point a, point b, point c);
- int main(void)
- {
- int n;
- scanf("%d", &n);
- point arr[n];
- for (int i = 0; i < n; i++)
- scanf("%lf %lf", &arr[i].x, &arr[i].y);
- double S = 0;
- for (int i = 1; i < n - 1; i++)
- {
- S += S_count(arr[0], arr[i], arr[i + 1]);
- }
- double S1 = 0;
- for (int i = 1; i < n - 1; i++)
- {
- S1 += S_count1(arr[0], arr[i], arr[i + 1]);
- }
- printf("%lf %lf", S, S1);
- return 0;
- }
- double S_count(point a, point b, point c)
- {
- double ab = sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
- double bc = sqrt((c.x - b.x) * (c.x - b.x) + (c.y - b.y) * (c.y - b.y));
- double ac = sqrt((c.x - a.x) * (c.x - a.x) + (c.y - a.y) * (c.y - a.y));
- double p = (ab + bc + ac) / 2;
- return sqrt(p * (p - ab) * (p - bc) * (p - ac));
- }
- double S_count1(point a, point b, point c)
- {
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement