[ 문제 ]
[ 접근방법 ]
신발끈 공식 을 통해 다각형의 넓이를 구한다.
[ 소스코드 ]
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int n;
vector<pair<double, double>> pos;
double ans = 0.0;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
pos.resize(n);
for(int i = 0; i < n; i++){
cin >> pos[i].first >> pos[i].second;
}
for(int i = 0; i < n - 1; i++){
ans = ans + pos[i].first * pos[i + 1].second - pos[i].second * pos[i + 1].first;
}
ans = ans + pos[n - 1].first * pos[0].second - pos[n - 1].second * pos[0].first;
ans = abs(ans) / 2;
cout << fixed;
cout.precision(1);
cout << ans;
return 0;
}
'PS' 카테고리의 다른 글
[ 백준 / C++ ] 5567 : 결혼식 (0) | 2024.11.05 |
---|---|
[ 백준 / C++ ] 2210 : 숫자판 점프 (0) | 2024.11.04 |
[ 백준 / C++ ] 2631 : 줄세우기 (0) | 2024.10.30 |
[ 백준 / C++ ] 10973 : 이전 순열 (0) | 2024.10.25 |
[ 백준 / C++ ] 15903 : 카드 합체 놀이 (0) | 2024.10.23 |