2166 areaOfPolygon
์๊ณ ๋ฆฌ์ฆ(๊ธฐํํ)
1. ์ฌ์ ์ ๋ฆฌ ์ฌ์ฉ
๊ตฌํ๋ฒ
1. ์ต๋ 4000000000000์ด ๋์ฌ ์ ์์ผ๋ฏ๋ก, int๋์ long long, float์ ์ฐ์ง๋ง๊ณ double๋ก ํต์ผ ์ํจ๋ค.
2. double์ ์ต๋ 15์๋ฆฌ์๋ฅผ ํํ๊ฐ๋ฅํ๋ฏ๋ก, ์ ๊ฐ๋ ์ถฉ๋ถํ ๋ค์ด๊ฐ ์ ์๋ค.
์ฝ๋
#include <iostream>
#include <cstdio>
#include <cmath>
#define MAX_POINT 10000
using namespace std;
typedef struct Point {
long long x;
long long y;
} Point;
Point point[MAX_POINT];
int numOfPoint;
double getAreaOfPolygon();
int main() {
cin >> numOfPoint;
for (int i = 0; i < numOfPoint; i++)
cin >> point[i].x >> point[i].y;
printf("%.1f", getAreaOfPolygon());
}
double getAreaOfPolygon() {
double area = 0;
for (int i = 0; i < numOfPoint - 1; i++)
area += ((point[i].x * point[i + 1].y) - (point[i + 1].x * point[i].y));
area += (point[numOfPoint - 1].x * point[0].y) - (point[0].x * point[numOfPoint - 1].y);
area = area < 0 ? (-1) * area : area;
return area /= 2;
}